WSContextFromLinkServer (C Function)
void * WSContextFromLinkServer(WSLinkServer s, int *err)
returns the context object associated with link server s when s was created.
Details
- 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().
Examples
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)
{
void *theContext;
int error;
WSActivate(link);
WSPutFunction(link,"Print",1);
WSPutString(link, "Hello Client Program");
WSEndPacket(link);
WSFlush(link);
theContext = WSContextFromLinkServer(server, &error);
if(error != WSEOK)
{ /* Handle error */ }
...
WSClose(link);
}