Remote Access¶
The NxLib can start a server to allow remote access from other processes. This is useful for debugging with NxTreeEdit and for applications that are split across several processes.
Opening a Port for Remote Access¶
Open a port for remote access using the C functions nxLibOpenTcpPort and nxLibCloseTcpPort or their equivalent in the language wrappers.
You can specify the port number you want to use. When you specify port 0, the NxLib will choose a free port from the range 24000–25000.
// Open the port for remote access.
int openedPort = 0;
nxLibOpenTcpPort(0, &openedPort);
// Let other processes connect...
// Close the port again.
nxLibCloseTcpPort();
// Open the port for remote access.
NXLIBINT openedPort = 0;
nxLibOpenTcpPort(&error, 0, &openedPort);
// Let other processes connect...
// Close the port again.
nxLibCloseTcpPort(&error);
# Open the port for remote access.
opened_port = nxlib.api.open_tcp_port(port_number=0)
# Let other processes connect...
# Close the port again.
nxlib.api.close_tcp_port()
// Open the port for remote access.
int openedPort;
NxLib.OpenTcpPort(0, out openedPort);
// Let other processes connect...
// Close the port again.
NxLib.CloseTcpPort();
Connecting to a Remote NxLib¶
To connect to the opened port, your program can use the NxLibRemote library instead of the normal NxLib. It provides the same C API, but all tree operations are forwarded to a remote NxLib instance. For managing the connections, this library provides the additional C functions nxLibConnect and nxLibDisconnect.
Before connecting, another process has to initialize an instance of the NxLib and open the remote connection port as described above.
// Connect to an NxLib instance on the local system.
nxLibConnect("127.0.0.1", 24000);
// Use the remote NxLib with the normal API...
// Disconnect from the remote NxLib.
nxLibDisconnect();
// Connect to an NxLib instance on the local system.
nxLibConnect(&error, "127.0.0.1", 24000);
// Use the remote NxLib with the normal API...
// Disconnect from the remote NxLib.
nxLibDisconnect(&error);
# Connect to an NxLib instance on the local system.
with NxLibRemote("127.0.0.1", 24000) as remote:
# Use the remote NxLib with the normal API...
pass
# The connection is closed automatically when exiting the with block.
The NxLibRemote interface is not available in the .NET language wrapper. Use NxTreeEdit or one of the other language interfaces to connect to a remote NxLib.