WPILibC++ 2023.4.3-108-ge5452e3
Client/Server Functions

Functions

unsigned int NT_GetNetworkMode (NT_Inst inst)
 Get the current network mode. More...
 
void NT_StartLocal (NT_Inst inst)
 Starts local-only operation. More...
 
void NT_StopLocal (NT_Inst inst)
 Stops local-only operation. More...
 
void NT_StartServer (NT_Inst inst, const char *persist_filename, const char *listen_address, unsigned int port3, unsigned int port4)
 Starts a server using the specified filename, listening address, and port. More...
 
void NT_StopServer (NT_Inst inst)
 Stops the server if it is running. More...
 
void NT_StartClient3 (NT_Inst inst, const char *identity)
 Starts a NT3 client. More...
 
void NT_StartClient4 (NT_Inst inst, const char *identity)
 Starts a NT4 client. More...
 
void NT_StopClient (NT_Inst inst)
 Stops the client if it is running. More...
 
void NT_SetServer (NT_Inst inst, const char *server_name, unsigned int port)
 Sets server address and port for client (without restarting client). More...
 
void NT_SetServerMulti (NT_Inst inst, size_t count, const char **server_names, const unsigned int *ports)
 Sets server addresses for client (without restarting client). More...
 
void NT_SetServerTeam (NT_Inst inst, unsigned int team, unsigned int port)
 Sets server addresses and port for client (without restarting client). More...
 
void NT_Disconnect (NT_Inst inst)
 Disconnects the client if it's running and connected. More...
 
void NT_StartDSClient (NT_Inst inst, unsigned int port)
 Starts requesting server address from Driver Station. More...
 
void NT_StopDSClient (NT_Inst inst)
 Stops requesting server address from Driver Station. More...
 
void NT_FlushLocal (NT_Inst inst)
 Flush local updates. More...
 
void NT_Flush (NT_Inst inst)
 Flush to network. More...
 
struct NT_ConnectionInfoNT_GetConnections (NT_Inst inst, size_t *count)
 Get information on the currently established network connections. More...
 
NT_Bool NT_IsConnected (NT_Inst inst)
 Return whether or not the instance is connected to another node. More...
 
int64_t NT_GetServerTimeOffset (NT_Inst inst, NT_Bool *valid)
 Get the time offset between server time and local time. More...
 

Detailed Description

Function Documentation

◆ NT_Disconnect()

void NT_Disconnect ( NT_Inst  inst)

Disconnects the client if it's running and connected.

This will automatically start reconnection attempts to the current server list.

Parameters
instinstance handle

◆ NT_Flush()

void NT_Flush ( NT_Inst  inst)

Flush to network.

Forces an immediate flush of all local entry changes to network. Normally this is done on a regularly scheduled interval (set by update rates on individual publishers).

Note: flushes are rate limited to avoid excessive network traffic. If the time between calls is too short, the flush will occur after the minimum time elapses (rather than immediately).

Parameters
instinstance handle

◆ NT_FlushLocal()

void NT_FlushLocal ( NT_Inst  inst)

Flush local updates.

Forces an immediate flush of all local changes to the client/server. This does not flush to the network.

Normally this is done on a regularly scheduled interval.

Parameters
instinstance handle

◆ NT_GetConnections()

struct NT_ConnectionInfo * NT_GetConnections ( NT_Inst  inst,
size_t *  count 
)

Get information on the currently established network connections.

If operating as a client, this will return either zero or one values.

Parameters
instinstance handle
countreturns the number of elements in the array
Returns
array of connection information

It is the caller's responsibility to free the array. The NT_DisposeConnectionInfoArray function is useful for this purpose.

◆ NT_GetNetworkMode()

unsigned int NT_GetNetworkMode ( NT_Inst  inst)

Get the current network mode.

Parameters
instinstance handle
Returns
Bitmask of NT_NetworkMode.

◆ NT_GetServerTimeOffset()

int64_t NT_GetServerTimeOffset ( NT_Inst  inst,
NT_Bool valid 
)

Get the time offset between server time and local time.

Add this value to local time to get the estimated equivalent server time. In server mode, this always returns a valid value of 0. In client mode, this returns the time offset only if the client and server are connected and have exchanged synchronization messages. Note the time offset may change over time as it is periodically updated; to receive updates as events, add a listener to the "time sync" event.

Parameters
instinstance handle
validset to true if the return value is valid, false otherwise (output)
Returns
Time offset in microseconds (if valid is set to true)

◆ NT_IsConnected()

NT_Bool NT_IsConnected ( NT_Inst  inst)

Return whether or not the instance is connected to another node.

Parameters
instinstance handle
Returns
True if connected.

◆ NT_SetServer()

void NT_SetServer ( NT_Inst  inst,
const char *  server_name,
unsigned int  port 
)

Sets server address and port for client (without restarting client).

Parameters
instinstance handle
server_nameserver name (UTF-8 string, null terminated)
portport to communicate over

◆ NT_SetServerMulti()

void NT_SetServerMulti ( NT_Inst  inst,
size_t  count,
const char **  server_names,
const unsigned int *  ports 
)

Sets server addresses for client (without restarting client).

The client will attempt to connect to each server in round robin fashion.

Parameters
instinstance handle
countlength of the server_names and ports arrays
server_namesarray of server names (each a UTF-8 string, null terminated)
portsarray of ports to communicate over (one for each server)

◆ NT_SetServerTeam()

void NT_SetServerTeam ( NT_Inst  inst,
unsigned int  team,
unsigned int  port 
)

Sets server addresses and port for client (without restarting client).

Connects using commonly known robot addresses for the specified team.

Parameters
instinstance handle
teamteam number
portport to communicate over

◆ NT_StartClient3()

void NT_StartClient3 ( NT_Inst  inst,
const char *  identity 
)

Starts a NT3 client.

Use NT_SetServer or NT_SetServerTeam to set the server name and port.

Parameters
instinstance handle
identitynetwork identity to advertise (cannot be empty string)

◆ NT_StartClient4()

void NT_StartClient4 ( NT_Inst  inst,
const char *  identity 
)

Starts a NT4 client.

Use NT_SetServer or NT_SetServerTeam to set the server name and port.

Parameters
instinstance handle
identitynetwork identity to advertise (cannot be empty string)

◆ NT_StartDSClient()

void NT_StartDSClient ( NT_Inst  inst,
unsigned int  port 
)

Starts requesting server address from Driver Station.

This connects to the Driver Station running on localhost to obtain the server IP address.

Parameters
instinstance handle
portserver port to use in combination with IP from DS

◆ NT_StartLocal()

void NT_StartLocal ( NT_Inst  inst)

Starts local-only operation.

Prevents calls to NT_StartServer or NT_StartClient from taking effect. Has no effect if NT_StartServer or NT_StartClient has already been called.

◆ NT_StartServer()

void NT_StartServer ( NT_Inst  inst,
const char *  persist_filename,
const char *  listen_address,
unsigned int  port3,
unsigned int  port4 
)

Starts a server using the specified filename, listening address, and port.

Parameters
instinstance handle
persist_filenamethe name of the persist file to use (UTF-8 string, null terminated)
listen_addressthe address to listen on, or null to listen on any address. (UTF-8 string, null terminated)
port3port to communicate over (NT3)
port4port to communicate over (NT4)

◆ NT_StopClient()

void NT_StopClient ( NT_Inst  inst)

Stops the client if it is running.

Parameters
instinstance handle

◆ NT_StopDSClient()

void NT_StopDSClient ( NT_Inst  inst)

Stops requesting server address from Driver Station.

Parameters
instinstance handle

◆ NT_StopLocal()

void NT_StopLocal ( NT_Inst  inst)

Stops local-only operation.

NT_StartServer or NT_StartClient can be called after this call to start a server or client.

◆ NT_StopServer()

void NT_StopServer ( NT_Inst  inst)

Stops the server if it is running.

Parameters
instinstance handle