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

server = WSTP`LinkServer`LinkServerCreate["[email protected]"];

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


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["[email protected]"];

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


Your Answer

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

Browse other questions tagged or ask your own question.