WSRegisterCallbackFunctionWithLinkServer()

void WSRegisterCallbackFunctionWithLinkServer(WSLinkServer s, WSNewLinkCallbackFunction f)
registers the callback function f with the link server s.

DetailsDetails

  • WSRegisterCallbackFunctionWithLinkServer() allows a program to 'install' a callback function f with a link server object s, so that when the link server receives an incoming connection, the link server will asynchronously notify the program of the new connection via the callback function.
  • The link server object will make callbacks to the callback function f asynchronously so the program must take care to protect access to shared data structures accessible through f from asynchrous access problems.
  • If the link server has more than one connection waiting in its connection queue, the link server will call the callback function f one time for each connection in its queue.

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (1)

#include "wstp.h"

void NewLinkCallbackFunction(WSLinkServer server, WSLINK link);

WSLinkServer startLinkServer(WSENV env)
{
    WSLinkServer theServer;
    int error;

    theServer = WSNewLinkServer(env, NULL /* No context object
        for this example */, &error);
    if(error != WSEOK)
    { /* Handle error */ }

    WSRegisterCallbackFunctionWithLinkServer(theServer,
        NewLinkCallbackFunction);

    return theServer;
}


void NewLinkCallbackFunction(WSLinkServer server, WSLINK link)
{
    WSActivate(link);
    WSPutFunction(link,"Print",1);
        WSPutString(link, "Hello Client Program");
    WSEndPacket(link);
    WSFlush(link);

    ...

    WSClose(link);
}