Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: checking for a dead MathLink connection

  • To: mathgroup at
  • Subject: [mg23668] Re: checking for a dead MathLink connection
  • From: tgayley at (Todd Gayley)
  • Date: Mon, 29 May 2000 12:23:59 -0400 (EDT)
  • Organization: Wolfram Research, Inc.
  • References: <8g5eed$>
  • Sender: owner-wri-mathgroup at


Use the function LinkError:

If[(LinkReadyQ[link]; First[LinkError[link]] =!= 0),
    (* link has a problem; close it. *)

Note the LinkReadyQ call before LinkError. LinkError itself does not actually "hit" the
link--it just looks at a stored error condition. Therefore you sometimes need to call a
function that touches the link for it to detect that an error has occurred. For example,
if the other side has died since the last time you used the link, LinkError will not
indicate an error. LinkReadyQ is a good do-nothing function that will force the link to
notice that an error has occurred. We are not interested in the return value of
LinkReadyQ, so we just ignore it.

The same consideration applies for C programmers: If you are polling MLError() to see if
an error has occurred, call MLReady() first. This is not an issue if another MathLink
function has already indicated that an error has occurred.


On 20 May 2000 03:21:49 -0400, Adalbert Hanssen <hanssen at> wrote:

>Hi, MathGroup,
>Links[] tells me, which MathLink connections were opened but not yet
>closed until the command is issued.
>Links["file"] tells me, which MathLink connections to "file.exe" (on NT) 
>were opened but not yet closed until the command is issued.
>Both return a List of LinkObjects (or {}, if there is none).
>After Uninstall[link], the link designated by the parameter is closed
>and after this, this connection is no longer reported by Links.
>If the other end of a MathLink connection "dies improperly", it is still
>reported by Links. 
>How can I tell, if a given link is alive? LinkReadyQ is not the right
>one, as it tests, if there are data to be read from the link. There
>must be some function, if you try to use a dead connection, you
>get an error message 
>LinkObject::linkn: "Argument LinkObject[....]... has an invalid 
>LinkObject number; the link may be dead."
>I just want the function which does the test resulting in the above
>error message, but before it is put out.
>Kind regards
>Dipl.-Math. Adalbert Hanszen

  • Prev by Date: Re: More Epilogs
  • Next by Date: RE: Reverse Axes in Plot
  • Previous by thread: Re: checking for a dead MathLink connection
  • Next by thread: Multiple Headers in Data File