OpenersNotesSection(Spacer1)Details

The link server creation functions (NonWLLink[WSNewLinkServer(), paclet:ref/c/WSNewLinkServer]), (NonWLLink[WSNewLinkServerWithPort(), paclet:ref/c/WSNewLinkServerWithPort]), and (NonWLLink[WSNewLinkServerWithPortAndInterface(), paclet:ref/c/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 (NonWLLink[WSNewLinkCallbackFunction, paclet:ref/c/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 (RefLink[wstp.h, paclet:ref/file/wstp.h]) and as returned by (NonWLLink[WSError(), paclet:ref/c/WSError]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)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);
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[WSNewLinkServer(), paclet:/ref/c/WSNewLinkServer])  ▪  (NonWLLink[WSNewLinkServerWithPort(), paclet:/ref/c/WSNewLinkServerWithPort])  ▪  (NonWLLink[ WSNewLinkServerWithPortAndInterface(), paclet:/ref/c/WSNewLinkServerWithPortAndInterface])  ▪  (NonWLLink[WSShutdownLinkServer(), paclet:/ref/c/WSShutdownLinkServer])  ▪  (NonWLLink[WSRegisterCallbackFunctionWithLinkServer(), paclet:/ref/c/WSRegisterCallbackFunctionWithLinkServer])  ▪  (NonWLLink[WSPortFromLinkServer(), paclet:/ref/c/WSPortFromLinkServer])  ▪  (NonWLLink[WSInterfaceFromLinkServer(), paclet:/ref/c/WSInterfaceFromLinkServer])  ▪  (NonWLLink[WSReleaseInterfaceFromLinkServer(), paclet:/ref/c/WSReleaseInterfaceFromLinkServer])}})}})