3
$\begingroup$

Suppose we create a link like this:

link = LinkCreate["mylink", LinkMode -> Listen]

How can we wait until this link gets connected to by another process, and time out if there's no incoming connection?

$\endgroup$
3
  • 3
    $\begingroup$ What I'm really looking for is confirmation that the answer below is correct! $\endgroup$
    – Szabolcs
    Jun 19, 2014 at 1:25
  • $\begingroup$ Related W Community thread. $\endgroup$
    – Szabolcs
    Jun 19, 2014 at 18:58
  • $\begingroup$ I can absolutely certify that the answer is correct (although incomplete...there is no timeout that I'm aware of). I'll add a bit more technical detail to the Community thread, where you ask slightly different questions and make a misleading assertion. But the answer as I now see it here is correct without qualification. $\endgroup$
    – John Fultz
    Jul 7, 2014 at 1:46

1 Answer 1

2
$\begingroup$

LinkActivate can be used for this. This Mathematica function is not documented, however the C version is.

From kernel 1, do

link = LinkCreate["mylink", LinkMode -> Listen]

LinkActivate[link] (* this will block and wait for an incoming connection *)

Now from kernel 2 (or another program, if using the C API), do

link = LinkConnect["mylink"]

LinkActivate[link] 
(* will return immediately; at this point LinkActivate in kernel 1 also returns *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.