OpenersNotesSection(Spacer1)Details

Sometimes it is useful to identify sides of a MathLink connection prior to setting up packet-based communication. Using (NonWLLink[MLSetEnvIDString(), paclet:ref/c/MLSetEnvIDString]) the developer can give an identification string for a program that will be exchanged every time a link is established with another program. (NonWLLink[MLGetLinkedEnvIDString(), paclet:ref/c/MLGetLinkedEnvIDString]) retrieves the other side of the link's name.

MLReleaseEnvIDString() is declared in the MathLink header file (RefLink[mathlink.h, paclet:ref/file/mathlink.h]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

#include <string.h>
#include "mathlink.h"

/* read the other side of the link's id string and check that it is "My Remote Program" */

int f(MLINK lp)
{
	int isCorrectProg;
	const char *envid;

	if(! MLGetLinkedEnvIDString(lp, &envid))
		{ /* unable to get remote side id from lp */ }

	isCorrectProg = strcmp(envid, "My Remote Program") == 0;

	MLReleaseEnvIDString(lp, envid, length);

	return isCorrectProg;
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[MLGetLinkedEnvIDString(), paclet:ref/c/MLGetLinkedEnvIDString])  ▪  (NonWLLink[MLSetEnvIDString(), paclet:ref/c/MLSetEnvIDString])}})}})