WPILibC++ 2024.3.2
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, std::string_view 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, std::string_view identity)
 Starts a NT3 client. More...
 
void nt::StartClient4 (NT_Inst inst, std::string_view 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::SetServer (NT_Inst inst, std::span< const std::pair< std::string_view, unsigned int > > servers)
 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...
 
std::vector< ConnectionInfont::GetConnections (NT_Inst inst)
 Get information on the currently established network connections. More...
 
bool nt::IsConnected (NT_Inst inst)
 Return whether or not the instance is connected to another node. More...
 
std::optional< int64_t > nt::GetServerTimeOffset (NT_Inst inst)
 Get the time offset between server time and local time. More...
 

Detailed Description

Function Documentation

◆ 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

◆ 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

◆ 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

◆ GetConnections()

std::vector< ConnectionInfo > nt::GetConnections ( NT_Inst  inst)

Get information on the currently established network connections.

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

Parameters
instinstance handle
Returns
array of connection information

◆ GetNetworkMode()

unsigned int nt::GetNetworkMode ( NT_Inst  inst)

Get the current network mode.

Parameters
instinstance handle
Returns
Bitmask of NT_NetworkMode.

◆ GetServerTimeOffset()

std::optional< int64_t > nt::GetServerTimeOffset ( NT_Inst  inst)

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 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
Returns
Time offset in microseconds (optional)

◆ IsConnected()

bool nt::IsConnected ( NT_Inst  inst)

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

Parameters
instinstance handle
Returns
True if connected.

◆ SetServer() [1/2]

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

◆ SetServer() [2/2]

void nt::SetServer ( NT_Inst  inst,
std::span< const std::pair< std::string_view, unsigned int > >  servers 
)

Sets server addresses for client (without restarting client).

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

Parameters
instinstance handle
serversarray of server name and port pairs

◆ 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

◆ StartClient3()

void nt::StartClient3 ( NT_Inst  inst,
std::string_view  identity 
)

Starts a NT3 client.

Use SetServer or SetServerTeam to set the server name and port.

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

◆ StartClient4()

void nt::StartClient4 ( NT_Inst  inst,
std::string_view  identity 
)

Starts a NT4 client.

Use SetServer or SetServerTeam to set the server name and port.

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

◆ 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

◆ StartLocal()

void nt::StartLocal ( NT_Inst  inst)

Starts local-only operation.

Prevents calls to StartServer or StartClient from taking effect. Has no effect if StartServer or StartClient has already been called.

◆ StartServer()

void nt::StartServer ( NT_Inst  inst,
std::string_view  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)

◆ StopClient()

void nt::StopClient ( NT_Inst  inst)

Stops the client if it is running.

Parameters
instinstance handle

◆ StopDSClient()

void nt::StopDSClient ( NT_Inst  inst)

Stops requesting server address from Driver Station.

Parameters
instinstance handle

◆ StopLocal()

void nt::StopLocal ( NT_Inst  inst)

Stops local-only operation.

StartServer or StartClient can be called after this call to start a server or client.

◆ StopServer()

void nt::StopServer ( NT_Inst  inst)

Stops the server if it is running.

Parameters
instinstance handle