Skip to content

setCONN

Jason Watkins edited this page May 8, 2015 · 4 revisions

Sets the port on which the client sends and receives data.

Syntax

Language Signature
C int setCONN(XPCSocket* sock, unsigned short port)
MATLAB setConn(port, socket)
Java void setCONN(int port))
Python setCONN(self, port)
Parameters

sock (C): The socket used to send the command.

port: The new port to use.

returns (C): A negative value if an error occurs, otherwise 0.

Remarks

This function exists primarily for backwards compatibility with old versions of the toolbox that always started out with the plugin sending data to the client on port 49055. In the current version, calling this function is nearly identical in effect to closing the existing client and reopening a new client using the new port. The only functional difference is that the plugin will recognize the client as a single continuous connection if setCONN is used.

Exceptions

C Error Code Java Exception Python Error Description
-1 IOException OSError The client is unable to send the command
-2 IOException OSError The client is unable to read the response

Examples

C
#include "xplaneConnect.h"

// Open the client using an OS specified port
XPCSocket sock = aopenUDP("127.0.0.1", 49007);

// Change the port to 49008
sock.setCONN(49008);

closeUDP(sock);

MATLAB

import XPlaneConnect.*

% Open client using default settings
socket = openUDP();

% Set client to use port 49008
socket.setCONN(49008);

closeUDP(socket);
Java
import gov.nasa.xpc.XPlaneConnect;

// Open a connection using the default port.
try(XPlaneConnect xpc = new XPlaneConnect())
{
    // Change port to 49008
    xpc.setCONN(49008);
}
Python
import xpc;

# Open a connection using the default port.
with xpc.XPlaneConnect() as client:
    # Change port to 49008
    client.setCONN(49008)