ProtonNet Server 1.0
An Open Solution for all your socket or web api needs.
Loading...
Searching...
No Matches
XmobiTea.ProtonNet.Client.Socket.SocketClientPeer Class Reference

Represents a client peer that manages socket connections, sends and receives operations, and handles various socket events such as connection, disconnection, and errors. Inherits from ClientPeer and implements ISocketClientPeer and IAfterAutoBind. More...

Inheritance diagram for XmobiTea.ProtonNet.Client.Socket.SocketClientPeer:
XmobiTea.ProtonNet.Client.ClientPeer XmobiTea.ProtonNet.Client.Socket.ISocketClientPeer XmobiTea.Bean.Support.IAfterAutoBind XmobiTea.ProtonNet.Client.IClientPeer XmobiTea.ProtonNet.Client.IClientPeer

Public Member Functions

 SocketClientPeer (string serverAddress, IClientPeerInitRequest initRequest, TcpClientOptions tcpClientOptions, UdpClientOptions udpClientOptions, TransportProtocol protocol)
 Initializes a new instance of the SocketClientPeer class for a specific transport protocol.
 
 SocketClientPeer (string serverAddress, IClientPeerInitRequest initRequest, TcpClientOptions tcpClientOptions, UdpClientOptions udpClientOptions, SslTransportProtocol sslProtocol, SslOptions sslOptions)
 Initializes a new instance of the SocketClientPeer class for a specific SSL transport protocol.
 
void OnAfterAutoBind ()
 Executes any additional logic after auto-binding of dependencies.
 
override INetworkStatistics GetNetworkStatistics ()
 Retrieves the network statistics associated with this socket client peer.
 
ISocketClient GetSocketClient ()
 Retrieves the underlying socket client associated with this peer.
 
void Send (OperationEvent operationEvent, SendParameters sendParameters)
 Sends an operation event to the server.
 
bool Connect (bool autoReconnect=false, OnConnected onConnected=null, OnDisconnected onDisconnected=null)
 Establishes a connection to the server.
 
bool Reconnect (bool autoReconnect=false, OnConnected onConnected=null, OnDisconnected onDisconnected=null)
 Reconnects to the server.
 
bool Disconnect ()
 Disconnects from the server.
 
override bool IsConnected ()
 Checks if the client peer is currently connected to the server.
 
override void Service ()
 Services the socket client peer, handling various events such as connection, disconnection, errors, and operation events.
 
- Public Member Functions inherited from XmobiTea.ProtonNet.Client.ClientPeer
 ClientPeer (string serverAddress, IClientPeerInitRequest initRequest, TcpClientOptions tcpClientOptions)
 Initializes a new instance of the ClientPeer class.
 
INetworkStatistics GetNetworkStatistics ()
 Abstract method to retrieve network statistics for the client peer. Must be implemented by derived classes.
 
int GetClientId ()
 Gets the unique client ID for this client peer.
 
int GetPing ()
 Gets the current ping (round-trip time) to the server.
 
int GetSendRate ()
 Gets the rate at which data is sent by this client peer.
 
void SetSendRate (int sendRate)
 Sets the rate at which data is sent by this client peer.
 
void Send (OperationRequest operationRequest, Action< OperationResponse > onOperationResponse, SendParameters sendParameters, int timeoutInSeconds)
 Sends an operation request to the server.
 
Task< OperationResponseSendAsync (OperationRequest operationRequest, SendParameters sendParameters=default, int timeoutInSeconds=15)
 Asynchronously sends an operation request to the server.
 
void SetDebugSupport (IDebugSupport debugSupport)
 Sets the debug support for this client peer.
 
void SetAuthToken (string authToken)
 Sets the authentication token for this client peer.
 
- Public Member Functions inherited from XmobiTea.ProtonNet.Client.IClientPeer
- Public Member Functions inherited from XmobiTea.ProtonNet.Client.Socket.ISocketClientPeer
- Public Member Functions inherited from XmobiTea.Bean.Support.IAfterAutoBind

Protected Member Functions

virtual ISocketPingPong NewSocketPingPong ()
 Creates a new instance of the ping-pong service for managing keep-alive pings.
 
virtual ISocketClient NewTcpClient (string host, int port, TcpClientOptions tcpClientOptions)
 Creates a new TCP socket client.
 
virtual ISocketClient NewSslClient (string host, int port, TcpClientOptions tcpClientOptions, SslOptions sslOptions)
 Creates a new SSL socket client.
 
virtual ISocketClient NewUdpClient (string host, int port, UdpClientOptions udpClientOptions)
 Creates a new UDP socket client.
 
virtual ISocketClient NewWsClient (string host, int port, TcpClientOptions tcpClientOptions)
 Creates a new WebSocket client.
 
virtual ISocketClient NewWssClient (string host, int port, TcpClientOptions tcpClientOptions, SslOptions sslOptions)
 Creates a new secure WebSocket client.
 
void OnSocketClientConnected ()
 Handles the socket client's connected event.
 
void OnSocketClientDisconnected ()
 Handles the socket client's disconnected event.
 
void OnSocketClientReceived (byte[] buffer, int position, int length)
 Handles the socket client's received event, processing incoming data.
 
void OnSocketClientError (System.Net.Sockets.SocketError error)
 Handles the socket client's error event.
 
virtual void OnAutoReconnect (int reconnectInSeconds)
 On AutoReconnect call to reconnect the socket.
 
override void SendOperation (OperationRequestPending operationRequestPending)
 Sends an operation request to the server.
 
virtual void SendOperation (OperationEventPending operationEventPending)
 Sends an operation event to the server.
 
void LogEnqueue (OperationEventPending operationEventPending)
 Logs the enqueuing of an operation event.
 
void LogSend (OperationEventPending operationEventPending)
 Logs the sending of an operation event.
 
void LogEvent (OperationEvent operationEvent)
 Logs the reception of an operation event.
 
- Protected Member Functions inherited from XmobiTea.ProtonNet.Client.ClientPeer
void AddWaitingResponseOperationRequestPending (OperationRequestPending operationRequestPending)
 Adds an operation request to the list of those waiting for a response.
 
OperationRequestPending CreateNewOperationRequestPending (OperationRequest operationRequest, Action< OperationResponse > onOperationResponse, SendParameters sendParameters, int timeoutInSeconds)
 Creates a new instance of OperationRequestPending for the given operation request.
 
void SendOperation (OperationRequestPending operationRequestPending)
 Abstract method to send an operation request to the server. Must be implemented by derived classes.
 
void LogEnqueue (OperationRequestPending operationRequestPending)
 Logs the enqueuing of an operation request.
 
void LogSend (OperationRequestPending operationRequestPending)
 Logs the sending of an operation request.
 
void LogRecv (OperationRequestPending operationRequestPending)
 Logs the reception of an operation response.
 

Protected Attributes

bool isHandshake = false
 Indicates whether the handshake has been completed.
 
bool autoReconnect = false
 Indicates whether auto-reconnect is enabled.
 

Properties

override string logPrefix [get]
 Prefix used in logging messages specific to this socket client peer.
 
ISocketSessionEmitService socketSessionEmitService [get]
 Service responsible for emitting socket session events.
 
ISocketOperationModelService operationModelService [get]
 Service responsible for handling operation models.
 
IEventService eventService [get]
 Service for handling various events within the client peer.
 
ISocketClient socketClient [get]
 The underlying socket client associated with this peer.
 
ISocketPingPong socketPingPong [get]
 Service responsible for managing the ping-pong operation to keep the connection alive.
 
OnConnected OnConnected [get, set]
 Event triggered when a connection is successfully established.
 
OnDisconnected OnDisconnected [get, set]
 Event triggered when a disconnection occurs.
 
OnOperationEvent OnOperationEvent [get, set]
 Event triggered when an operation event is received.
 
OnError OnError [get, set]
 Event triggered when a socket error occurs.
 
object _lockOperationEventPending [get]
 Lock object for synchronizing access to pending operation events.
 
OnConnected onImmediatelyConnected [get, set]
 Callback for immediate connection events.
 
OnDisconnected onImmediatelyDisconnected [get, set]
 Callback for immediate disconnection events.
 
object _lockOther [get]
 Lock object for synchronizing access to other fields.
 
bool isDisconnectedNotice [get, set]
 Indicates if a disconnection notice has been sent.
 
bool isConnectedNotice [get, set]
 Indicates if a connection notice has been sent.
 
bool isErrorNotice [get, set]
 Indicates if an error notice has been sent.
 
System.Net.Sockets.SocketError socketError [get, set]
 The socket error that occurred.
 
DisconnectReason disconnectReason [get, set]
 The reason for the disconnection.
 
string disconnectMessage [get, set]
 The message describing the disconnection.
 
string serverSessionId [get]
 The session ID provided by the server.
 
int connectionId [get]
 The connection ID assigned to this peer.
 
byte[] encryptKey [get]
 The encryption key used for securing communications.
 
Task reconnectTask [get, set]
 Task for managing reconnection attempts.
 
int autoReconnectInSeconds [get, set]
 The delay in seconds before attempting to auto-reconnect.
 
int reconnectCount [get, set]
 The current count of reconnection attempts.
 
UdpClientOptions udpClientOptions [get]
 Options for configuring the UDP client.
 
- Properties inherited from XmobiTea.ProtonNet.Client.ClientPeer
string logPrefix [get]
 Prefix used in logging messages specific to this client peer.
 
ILogger logger [get]
 Logger instance for logging activities within the client peer.
 
object _lockWaitingResponseOperationRequestPendings [get]
 Lock object to synchronize access to waiting response operation requests.
 
List< OperationRequestPendingwaitingResponseOperationRequestPendings [get]
 List of operation requests that are awaiting a response from the server.
 
object _lockNeedRemoveOperationRequestPendings [get]
 Lock object to synchronize access to operation requests that need to be removed.
 
IDebugSupport debugSupport [get, set]
 Debug support instance for logging and monitoring operations.
 
float updateInterval [get]
 Interval at which updates are sent, in seconds.
 
string authToken [get]
 Authentication token used for server communication.
 
string serverAddress [get]
 Address of the server to which this client peer is connected.
 
string sessionId [get]
 Session ID for the current connection session.
 
int clientId [get]
 Unique client ID assigned to this client peer.
 
IRpcProtocolService rpcProtocolService [get, set]
 RPC protocol service used by this client peer.
 
TcpClientOptions tcpClientOptions [get]
 Options for configuring TCP client connections.
 
- Properties inherited from XmobiTea.ProtonNet.Client.Socket.ISocketClientPeer

Detailed Description

Represents a client peer that manages socket connections, sends and receives operations, and handles various socket events such as connection, disconnection, and errors. Inherits from ClientPeer and implements ISocketClientPeer and IAfterAutoBind.

Member Function Documentation

◆ Connect()

bool XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.Connect ( bool autoReconnect = false,
OnConnected onConnected = null,
OnDisconnected onDisconnected = null )

Establishes a connection to the server.

Parameters
autoReconnectSpecifies whether to automatically reconnect if the connection is lost.
onConnectedCallback for handling successful connections.
onDisconnectedCallback for handling disconnections.
Returns
True if the connection was successfully established, otherwise false.

Implements XmobiTea.ProtonNet.Client.Socket.ISocketClientPeer.

◆ Disconnect()

bool XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.Disconnect ( )

Disconnects from the server.

Returns
True if the disconnection was successful, otherwise false.

Implements XmobiTea.ProtonNet.Client.Socket.ISocketClientPeer.

◆ GetNetworkStatistics()

override INetworkStatistics XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.GetNetworkStatistics ( )

Retrieves the network statistics associated with this socket client peer.

Returns
An instance of INetworkStatistics representing the network statistics.

Implements XmobiTea.ProtonNet.Client.IClientPeer.

◆ GetSocketClient()

ISocketClient XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.GetSocketClient ( )

Retrieves the underlying socket client associated with this peer.

Returns
An instance of ISocketClient representing the socket client.

Implements XmobiTea.ProtonNet.Client.Socket.ISocketClientPeer.

◆ IsConnected()

override bool XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.IsConnected ( )
virtual

Checks if the client peer is currently connected to the server.

Returns
True if connected, otherwise false.

Reimplemented from XmobiTea.ProtonNet.Client.ClientPeer.

◆ LogEnqueue()

void XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.LogEnqueue ( OperationEventPending operationEventPending)
protected

Logs the enqueuing of an operation event.

Parameters
operationEventPendingThe pending operation event that was enqueued.

◆ LogEvent()

void XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.LogEvent ( OperationEvent operationEvent)
protected

Logs the reception of an operation event.

Parameters
operationEventThe operation event that was received.

◆ LogSend()

void XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.LogSend ( OperationEventPending operationEventPending)
protected

Logs the sending of an operation event.

Parameters
operationEventPendingThe pending operation event that was sent.

◆ NewSocketPingPong()

virtual ISocketPingPong XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.NewSocketPingPong ( )
protectedvirtual

Creates a new instance of the ping-pong service for managing keep-alive pings.

Returns
An instance of ISocketPingPong.

◆ NewSslClient()

virtual ISocketClient XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.NewSslClient ( string host,
int port,
TcpClientOptions tcpClientOptions,
SslOptions sslOptions )
protectedvirtual

Creates a new SSL socket client.

Parameters
hostThe host address of the server.
portThe port number to connect to.
tcpClientOptionsOptions for configuring the TCP client.
sslOptionsThe Ssl options containing the certificate and other SSL-related settings.
Returns
An instance of ISocketClient representing the SSL client.

◆ NewTcpClient()

virtual ISocketClient XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.NewTcpClient ( string host,
int port,
TcpClientOptions tcpClientOptions )
protectedvirtual

Creates a new TCP socket client.

Parameters
hostThe host address of the server.
portThe port number to connect to.
tcpClientOptionsOptions for configuring the TCP client.
Returns
An instance of ISocketClient representing the TCP client.

◆ NewUdpClient()

virtual ISocketClient XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.NewUdpClient ( string host,
int port,
UdpClientOptions udpClientOptions )
protectedvirtual

Creates a new UDP socket client.

Parameters
hostThe host address of the server.
portThe port number to connect to.
udpClientOptionsOptions for configuring the UDP client.
Returns
An instance of ISocketClient representing the UDP client.

◆ NewWsClient()

virtual ISocketClient XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.NewWsClient ( string host,
int port,
TcpClientOptions tcpClientOptions )
protectedvirtual

Creates a new WebSocket client.

Parameters
hostThe host address of the server.
portThe port number to connect to.
tcpClientOptionsOptions for configuring the WebSocket client.
Returns
An instance of ISocketClient representing the WebSocket client.

◆ NewWssClient()

virtual ISocketClient XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.NewWssClient ( string host,
int port,
TcpClientOptions tcpClientOptions,
SslOptions sslOptions )
protectedvirtual

Creates a new secure WebSocket client.

Parameters
hostThe host address of the server.
portThe port number to connect to.
tcpClientOptionsOptions for configuring the WebSocket client.
sslOptionsThe Ssl options containing the certificate and other SSL-related settings.
Returns
An instance of ISocketClient representing the secure WebSocket client.

◆ OnAfterAutoBind()

void XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.OnAfterAutoBind ( )

Executes any additional logic after auto-binding of dependencies.

Implements XmobiTea.Bean.Support.IAfterAutoBind.

◆ OnAutoReconnect()

virtual void XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.OnAutoReconnect ( int reconnectInSeconds)
protectedvirtual

On AutoReconnect call to reconnect the socket.

Parameters
reconnectInSecondsThe reconnectInSeconds after

◆ OnSocketClientError()

void XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.OnSocketClientError ( System.Net.Sockets.SocketError error)
protected

Handles the socket client's error event.

Parameters
errorThe socket error encountered.

◆ OnSocketClientReceived()

void XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.OnSocketClientReceived ( byte[] buffer,
int position,
int length )
protected

Handles the socket client's received event, processing incoming data.

Parameters
bufferThe buffer containing the received data.
positionThe starting position in the buffer.
lengthThe length of the data in the buffer.

◆ Reconnect()

bool XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.Reconnect ( bool autoReconnect = false,
OnConnected onConnected = null,
OnDisconnected onDisconnected = null )

Reconnects to the server.

Parameters
autoReconnectSpecifies whether to automatically reconnect if the connection is lost.
onConnectedCallback for handling successful connections.
onDisconnectedCallback for handling disconnections.
Returns
True if the reconnection was successful, otherwise false.

Implements XmobiTea.ProtonNet.Client.Socket.ISocketClientPeer.

◆ Send()

void XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.Send ( OperationEvent operationEvent,
SendParameters sendParameters )

Sends an operation event to the server.

Parameters
operationEventThe operation event to send.
sendParametersThe parameters used for sending the event.

Implements XmobiTea.ProtonNet.Client.Socket.ISocketClientPeer.

◆ SendOperation() [1/2]

virtual void XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.SendOperation ( OperationEventPending operationEventPending)
protectedvirtual

Sends an operation event to the server.

Parameters
operationEventPendingThe pending operation event to send.

◆ SendOperation() [2/2]

override void XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.SendOperation ( OperationRequestPending operationRequestPending)
protected

Sends an operation request to the server.

Parameters
operationRequestPendingThe pending operation request to send.

◆ Service()

override void XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.Service ( )
virtual

Services the socket client peer, handling various events such as connection, disconnection, errors, and operation events.

Reimplemented from XmobiTea.ProtonNet.Client.ClientPeer.

Property Documentation

◆ OnConnected

OnConnected XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.OnConnected
getset

Event triggered when a connection is successfully established.

Implements XmobiTea.ProtonNet.Client.Socket.ISocketClientPeer.

◆ OnDisconnected

OnDisconnected XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.OnDisconnected
getset

Event triggered when a disconnection occurs.

Implements XmobiTea.ProtonNet.Client.Socket.ISocketClientPeer.

◆ OnError

OnError XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.OnError
getset

Event triggered when a socket error occurs.

Implements XmobiTea.ProtonNet.Client.Socket.ISocketClientPeer.

◆ OnOperationEvent

OnOperationEvent XmobiTea.ProtonNet.Client.Socket.SocketClientPeer.OnOperationEvent
getset

Event triggered when an operation event is received.

Implements XmobiTea.ProtonNet.Client.Socket.ISocketClientPeer.


The documentation for this class was generated from the following file: