OpenersNotesSection(Spacer1)Details

The function WSResolveLinkService() initiates a resolve operation on the network to convert a WSTP service name to the connection details necessary for establishing a link to the service. WSResolveLinkService() starts the operation and returns immediately. The WSTP library delivers the connection details asynchronously to the application via a function of type WSResolveCallbackFunction.

An WSResolveLinkService function has the following form:

void function(WSENV e, WSServiceRef r, const char *serviceName, const char *linkName, const char *protocol, int options, void *context);

Because WSTP link services primarily involve services available via the network, the protocol option will almost always be "TCPIP".

The combination of the link name, protocol, and options argument is sufficient to create a link that will connect to the named service. The link must be created in connect mode using either -linkmode connect or -linkconnect.

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

#include <string.h> /* for memset, memcpy, etc... */
#include <stdio.h> /* for snprintf */
#include "wstp.h"

void ResolveCallbackFunction(WSENV e, WSServiceRef r, const char *serviceName, const char *linkName, const char *protocol, int options, void *context);

WSServiceRef startResolvingServiceWithName(WSENV e, const char *name)
{
	WSServiceRef theRef;
	int apiResult = 0;

	apiResult = WSResolveLinkService(e, ResolveCallbackFunction, name,
		NULL /* No context object for this example */, &theRef);
	if(apiResult != 0)
	{ /* Handle the error */ }

	return theRef;
}


void ResolveCallbackFunction(WSENV e, WSServiceRef r, const char *serviceName, const char *linkName, const char *protocol, int options, void *context)
{
	WSLINK newLink = (WSLINK)0;
	int error = 0;
	int argc = 0;
	const char *argv[] = {
		"Dummy value representing program name",
		"-linkname",
		(const char *)0,
		"-linkprotocol",
		(const char *)0,
		"-linkconnect",
		"-linkoptions",
		(const char *)0,
		/* The following NULL pointer terminates the argv array */
		(const char *)0 
	};

	char optionsBuffer[50];

	memset((void *)optionsBuffer, 0, sizeof(char) * 50));

	snprintf(optionsBuffer, 50, "%d", options);

	argv[2] = linkName;
	argv[4] = protocol;
	argv[7] = (const char *)optionsBuffer;

	argc = 8;

	newLink = WSOpenArgcArgv(e, argc, argv, &error);
	if(newLink == (WSLINK)0 || error != WSEOK)
	{ /* Handle the error */ }

	/* ... */

	return;
}

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[WSTP C API Developer Guide (Mac OS X), paclet:tutorial/WSTPDeveloperGuide-MacintoshOverview])}, {▪(RefLinkPlain[WSTP C API Developer Guide (Unix and Linux), paclet:tutorial/WSTPDeveloperGuide-UnixOverview])}, {▪(RefLinkPlain[WSTP C API Developer Guide (Windows), paclet:tutorial/WSTPDeveloperGuide-WindowsOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Alphabetical Listing of WSTP C Functions, paclet:guide/AlphabeticalListingOfWSTPCFunctions])}, {▪(RefLinkPlain[Low-Level WSTP Operations, paclet:guide/LowLevelWSTPOperations])}, {▪(RefLinkPlain[WSTP C Language Functions, paclet:guide/WSTPCLanguageFunctions])}})}})