WSContextFromLinkServer (C Function)

void * WSContextFromLinkServer(WSLinkServer s, int *err)

returns the context object associated with link server s when s was created.


  • The link server creation functions WSNewLinkServer(), WSNewLinkServerWithPort(), and WSNewLinkServerWithPortAndInterface() all allow the caller to pass an opaque context object to the link server. The context object can be any object needed by the application to handle incoming connections from the link server. The context object is most useful when used with the WSNewLinkCallbackFunction mechanism.
  • If WSContextFromLinkServer() encounters an error it will return the error value in err and return (void *)0. If WSContextFromLinkServer() succeeds, err will contain zero.
  • The nonzero values that indicate an error condition correspond to the WSE error codes in wstp.h and as returned by WSError().


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 */ }


    return theServer;

void NewLinkCallbackFunction(WSLinkServer server, WSLINK link)
    void *theContext;
    int error;

        WSPutString(link, "Hello Client Program");

    theContext = WSContextFromLinkServer(server, &error);
    if(error != WSEOK)
    { /* Handle error */ }