class
NetworkPeer
Represents a single peer in a network hierarchy.
Allows you to create a server that listens for incoming connections, or connect as a client to a remote server. Supports sending and receiving messages with configurable reliability and ordering guarantees.
Public
Constructors
NetworkPeer
Methods
~NetworkPeer
StartServer
Starts the peer as a server, listening for incoming connections on the specified port.
- port
- Port to listen on.
- maxConnections
- Maximum number of simultaneous connections allowed.
Returns: True if the server started successfully, false otherwise.
Connect
Connects to a remote server as a client.
- address
- Network address of the server to connect to.
Returns: Connection ID that will be valid once connection completes, or Invalid if the connection attempt failed to start.
Disconnect
Disconnects from a specific peer.
- connection
- Connection ID to disconnect.
DisconnectAll
Disconnects all connected peers and shuts down the peer.
PollMessages
Polls for new messages received from the network.
Messages are appended to the provided container.
Example:
- outMessages
- Container to fill with received messages. Will be cleared before filling. Users should maintain a persistent container to avoid per-frame allocations.
- maxMessages
- Maximum number of messages to retrieve in a single poll.
SendMessage
Sends a message to a specific connection.
- connection
- Connection ID to send to.
- data
- Pointer to message data. First byte should be the message type.
- size
- Size of the message data in bytes.
- flags
- Flags controlling send behavior (reliability, priority, etc.).
BroadcastMessage
Broadcasts a message to all connected peers.
- data
- Pointer to message data. First byte should be the message type.
- size
- Size of the message data in bytes.
- flags
- Flags controlling send behavior (reliability, priority, etc.).
GetConnectionInfo
Retrieves connection quality information for a specific connection.
- connection
- Connection to query.
- outInfo
- Structure to fill with connection information.
Returns: True if connection info was retrieved successfully, false if connection is invalid.
IsConnected
Checks if a connection is currently active.
- connection
- Connection to check.
Returns: True if connected, false otherwise.
GetConnectionState
Retrieves the current state of a connection.
- connection
- Connection to query.
Returns: Current connection state.
FreeMessage
Frees a message received via PollMessages.
Must be called for each message after processing.
- message
- Message to free.