2
$\begingroup$

In this question, @Todd Gayley provided a nice snippet for WSTP server.

server = WSTP`LinkServer`LinkServerCreate["8000@127.0.0.1"];

While[$KeepRunning =!= False,
    links = WSTP`LinkServer`GetLinks[server];
    If[Length[links] > 0,
        Print["Client connecting"];
        MathLink`AddSharingLink[#, MathLink`AllowPreemptive->True, MathLink`ImmediateStart->True]& /@ links;
    ];
    Pause[0.1]
]

WSTP`LinkServer`LinkServerClose[server]

But Pause[0.1] looks hacky here. In WSTP C API, we have WSRegisterCallbackFunctionWithLinkServer for asynchronous callback purpose. Is it possible to do the same with pure WL?

For example, I hope the following would work:

server = WSTP`LinkServer`LinkServerCreate["8000@127.0.0.1"];

fnCallback[link_LinkObject] := doStuffWithLink[link];
WSTP`LinkServer`RegisterCallback[server, fnCallback];
$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.