API: Init: Inter Machine

Matt Clarke edited this page Apr 24, 2017 · 3 revisions

The inter-machine API allows connections between processes on both the same machine, and over a network, via BSD sockets. Note though there are differences to the API if you wish to connect to a server process not in the local network.

Client

In the client process, you may connect to a server process by allowing the system to automatically find its broadcasted service name via Bonjour, or you can connect to it on a specific hostname and port number.

To connect to a server process via Bonjour:

NSError *error;
NSString *serviceName = @"<unique_name>";
[DCNSClient initialiseToRemoteWithService:serviceName authenticationDelegate:auth andError:&error];

Where:
auth is either nil, or an object that responds to DCNSConnectionDelegate to provide your own security.
error will contain information about errors setting up the library, if any.
serviceName is a unique name the server process makes classes available on.

Note the similarity with the API to connect to a server process on only the local machine, here.

Connecting to a specific hostname and port number does have some caveats; mainly, IPv4 addresses are currently unsupported outside of the local network, due to NAT.

The API for this is:

NSError *error;
NSString *hostName = @"<hostname>";
unsigned int portNumber = 42563;
[DCNSClient initialiseToRemoteWithHostname:hostName portNumber:portNumber authenticationDelegate:auth andError:&error];

Where:
auth is either nil, or an object that responds to DCNSConnectionDelegate to provide your own security.
error will contain information about errors setting up the library, if any.
hostName is the hostname the server is available on. This is may be the exact IP address of the server, or its domain name. If it is the domain name, the IPv6 address for the server will be attempted to be resolved.
portNumber is the port number the server process is listening on for connections.

Server

The server process uses the same API call whether it will be connected to via Bonjour or a specific hostname by the client.

To setup the server process:

NSError *error;
NSString *serviceName = @"<unique_name>";
unsigned int portNumber = 42563;
[DCNSServer initialiseAsRemoteWithService:serviceName portNumber:portNumber authenticationDelegate:auth andError:&error];

Where:
auth is either nil, or an object that responds to DCNSConnectionDelegate to provide your own security.
error will contain information about errors setting up the library, if any.
serviceName is a unique name the server process makes classes available on.
portNumber is the port number the server process will listen on for connections. You may pass 0 here to assign any available port number.

See API: Options: Security for more information regarding security, such as how to provide your own.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.