Interface INetworkTransport
Defines the contract for a network transport that supports both server and client communication.
public interface INetworkTransport
Properties
ConnectionCount
Gets the number of currently active connections.
int ConnectionCount { get; }
Property Value
InstanceId
Gets the unique identifier for this transport instance.
Guid InstanceId { get; }
Property Value
Methods
Connect(IPEndPoint, ProtocolType)
Connects to the specified endpoint using the specified protocol.
bool Connect(IPEndPoint endPoint, ProtocolType protocolType)
Parameters
endPointIPEndPointThe remote endpoint to connect to.
protocolTypeProtocolTypeThe protocol type to use for the connection.
Returns
- bool
trueif the connection was initiated successfully; otherwise,false.
Connect(ConnectionParameters)
Connects using the specified connection parameters.
bool Connect(ConnectionParameters pars)
Parameters
parsConnectionParametersThe connection parameters.
Returns
- bool
trueif the connection was initiated successfully; otherwise,false.
Disconnect(IPProtoEndPoint)
Disconnects the specified endpoint.
void Disconnect(IPProtoEndPoint endPoint)
Parameters
endPointIPProtoEndPointThe endpoint to disconnect.
GetStatistics(IPProtoEndPoint)
Gets the connection statistics for the specified endpoint.
TransportStat GetStatistics(IPProtoEndPoint endPoint)
Parameters
endPointIPProtoEndPointThe endpoint to get statistics for.
Returns
- TransportStat
The transport statistics, or
nullif the endpoint is not found.
Send(IPProtoEndPoint, VersatileBuffer)
Sends data to the specified endpoint.
SendResult Send(IPProtoEndPoint endPoint, VersatileBuffer packet)
Parameters
endPointIPProtoEndPointThe endpoint to send data to.
packetVersatileBufferThe data buffer to send.
Returns
- SendResult
The result of the send operation.
Exceptions
- Exception
Thrown when the endpoint is not found in the active connections.
Send(IPProtoEndPoint, IPProtoEndPoint, VersatileBuffer)
Sends data from a local endpoint to a remote endpoint.
SendResult Send(IPProtoEndPoint localEndPoint, IPProtoEndPoint remoteEndPoint, VersatileBuffer packet)
Parameters
localEndPointIPProtoEndPointThe local endpoint to send data from.
remoteEndPointIPProtoEndPointThe remote endpoint to send data to.
packetVersatileBufferThe data buffer to send.
Returns
- SendResult
The result of the send operation.
Remarks
This method is primarily intended for UDP connections where the local endpoint matters.
Exceptions
- Exception
Thrown when the local endpoint is not found in the active connections.
Start()
Starts the transport, enabling it to accept connections and process data.
void Start()
StartListen(IPEndPoint, ProtocolType)
Starts listening for incoming connections on the specified endpoint.
void StartListen(IPEndPoint serverEndPoint, ProtocolType protocolType)
Parameters
serverEndPointIPEndPointThe server endpoint to listen on.
protocolTypeProtocolTypeThe protocol type to use (TCP or UDP).
StartListen(ConnectionParameters)
Starts listening for incoming connections using the specified parameters.
void StartListen(ConnectionParameters pars)
Parameters
parsConnectionParametersThe connection parameters including the endpoint configuration.
Stop()
Stops the transport and closes all active connections.
void Stop()
StopListen(IPProtoEndPoint)
Stops listening on the specified endpoint.
void StopListen(IPProtoEndPoint serverEndPoint)
Parameters
serverEndPointIPProtoEndPointThe endpoint to stop listening on.
Update(IPProtoEndPoint, ConnectionParameters)
Updates connection parameters for an existing connection.
void Update(IPProtoEndPoint endPoint, ConnectionParameters pars)
Parameters
endPointIPProtoEndPointThe endpoint to update parameters for.
parsConnectionParametersThe new connection parameters.
Remarks
Only parameters that can be changed after a connection is established will be updated.
Events
Connected
Occurs when a new client connects or a listener starts successfully.
event EventHandler<TransportArgs> Connected
Event Type
Disconnected
Occurs when a connected client disconnects or a connection is closed.
event EventHandler<TransportArgs> Disconnected
Event Type
Received
Occurs when new data is received from a connection.
event EventHandler<TransportArgs> Received
Event Type
Sent
Occurs when data has been sent successfully.
event EventHandler<TransportArgs> Sent