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

Implements a TCP client for connecting to a server, sending, and receiving data. Provides both synchronous and asynchronous operations. More...

Inheritance diagram for XmobiTea.ProtonNetClient.TcpClient:
XmobiTea.ProtonNetClient.ITcpClient XmobiTea.ProtonNetClient.IClient XmobiTea.ProtonNet.Client.Socket.Clients.SocketTcpClient XmobiTea.ProtonNetClient.HttpClient XmobiTea.ProtonNetClient.WsClient XmobiTea.ProtonNet.Client.Socket.Clients.SocketWsClient

Public Member Functions

 TcpClient (string address, int port, TcpClientOptions options)
 Initializes a new instance of the TcpClient class.
 
INetworkStatistics GetNetworkStatistics ()
 Gets the network statistics associated with the client.
 
virtual bool Connect ()
 Connects the client to the server synchronously.
 
virtual bool Disconnect ()
 Disconnects the client from the server synchronously.
 
virtual bool Reconnect ()
 Reconnects the client to the server by first disconnecting and then reconnecting.
 
virtual bool ConnectAsync ()
 Connects the client to the server asynchronously.
 
virtual bool DisconnectAsync ()
 Disconnects the client from the server asynchronously.
 
virtual bool ReconnectAsync ()
 Reconnects the client to the server asynchronously by first disconnecting and then reconnecting.
 
virtual int Send (byte[] buffer)
 Sends data to the server synchronously.
 
virtual int Send (byte[] buffer, int position, int length)
 Sends data to the server synchronously starting from a specific position in the buffer.
 
virtual bool SendAsync (byte[] buffer)
 Sends data to the server asynchronously.
 
virtual bool SendAsync (byte[] buffer, int position, int length)
 Sends data to the server asynchronously starting from a specific position in the buffer.
 
void Dispose ()
 Disposes the TCP client, releasing all resources.
 
- Public Member Functions inherited from XmobiTea.ProtonNetClient.IClient

Protected Member Functions

virtual void OnConnecting ()
 Called when the client is in the process of connecting. Can be overridden in derived classes to handle the event.
 
virtual void OnConnected ()
 Called when the client has successfully connected to the server. Can be overridden in derived classes to handle the event.
 
virtual void OnDisconnecting ()
 Called when the client is in the process of disconnecting. Can be overridden in derived classes to handle the event.
 
virtual void OnDisconnected ()
 Called when the client has successfully disconnected from the server. Can be overridden in derived classes to handle the event.
 
virtual void OnReceived (byte[] buffer, int position, int length)
 Called when data is received from the server. Can be overridden in derived classes to handle the event.
 
virtual void OnSent (int sent, int pending)
 Called when data is successfully sent to the server. Can be overridden in derived classes to handle the event.
 
virtual void OnEmpty ()
 Called when the send buffer is empty. Can be overridden in derived classes to handle the event.
 
virtual void OnError (SocketError error)
 Called when an error occurs during socket operations. Can be overridden in derived classes to handle the event.
 
virtual void Dispose (bool disposingManagedResources)
 Disposes the TCP client, releasing managed resources if specified.
 

Properties

string Id [get]
 Gets the unique identifier for this TCP client instance.
 
string Address [get]
 Gets the server address to which the client is connected.
 
int Port [get]
 Gets the port number on the server to which the client is connected.
 
EndPoint EndPoint [get]
 Gets the endpoint representing the server's address and port.
 
Socket Socket [get]
 Gets the underlying socket used for the connection.
 
TcpClientOptions Options [get]
 Gets the options used to configure the TCP client.
 
bool IsConnecting [get]
 Gets a value indicating whether the client is currently connecting.
 
bool IsConnected [get]
 Gets a value indicating whether the client is connected to the server.
 
bool IsDisposed [get]
 Gets a value indicating whether the client has been disposed.
 
bool IsSocketDisposed [get]
 Gets a value indicating whether the socket has been disposed.
 

Detailed Description

Implements a TCP client for connecting to a server, sending, and receiving data. Provides both synchronous and asynchronous operations.

Constructor & Destructor Documentation

◆ TcpClient()

XmobiTea.ProtonNetClient.TcpClient.TcpClient ( string address,
int port,
TcpClientOptions options )

Initializes a new instance of the TcpClient class.

Parameters
addressThe server address to connect to.
portThe port number on the server.
optionsTCP client options for configuring the connection.

Member Function Documentation

◆ Connect()

virtual bool XmobiTea.ProtonNetClient.TcpClient.Connect ( )
virtual

Connects the client to the server synchronously.

Returns
True if the connection is successful; otherwise, false.

Implements XmobiTea.ProtonNetClient.IClient.

Reimplemented in XmobiTea.ProtonNet.Client.Socket.Clients.SocketTcpClient, XmobiTea.ProtonNet.Client.Socket.Clients.SocketWsClient, and XmobiTea.ProtonNetClient.WsClient.

◆ ConnectAsync()

virtual bool XmobiTea.ProtonNetClient.TcpClient.ConnectAsync ( )
virtual

Connects the client to the server asynchronously.

Returns
True if the connection is successful; otherwise, false.

Implements XmobiTea.ProtonNetClient.IClient.

Reimplemented in XmobiTea.ProtonNetClient.WsClient.

◆ Disconnect()

virtual bool XmobiTea.ProtonNetClient.TcpClient.Disconnect ( )
virtual

Disconnects the client from the server synchronously.

Returns
True if the disconnection is successful; otherwise, false.

Implements XmobiTea.ProtonNetClient.IClient.

Reimplemented in XmobiTea.ProtonNet.Client.Socket.Clients.SocketTcpClient, and XmobiTea.ProtonNet.Client.Socket.Clients.SocketWsClient.

◆ DisconnectAsync()

virtual bool XmobiTea.ProtonNetClient.TcpClient.DisconnectAsync ( )
virtual

Disconnects the client from the server asynchronously.

Returns
True if the disconnection is successful; otherwise, false.

Implements XmobiTea.ProtonNetClient.IClient.

◆ Dispose()

virtual void XmobiTea.ProtonNetClient.TcpClient.Dispose ( bool disposingManagedResources)
protectedvirtual

Disposes the TCP client, releasing managed resources if specified.

Parameters
disposingManagedResourcesTrue to release managed resources; otherwise, false.

◆ GetNetworkStatistics()

INetworkStatistics XmobiTea.ProtonNetClient.TcpClient.GetNetworkStatistics ( )

Gets the network statistics associated with the client.

Returns
An object implementing INetworkStatistics containing network statistics.

Implements XmobiTea.ProtonNetClient.IClient.

◆ OnConnected()

virtual void XmobiTea.ProtonNetClient.TcpClient.OnConnected ( )
protectedvirtual

Called when the client has successfully connected to the server. Can be overridden in derived classes to handle the event.

Reimplemented in XmobiTea.ProtonNet.Client.Socket.Clients.SocketTcpClient, and XmobiTea.ProtonNetClient.WsClient.

◆ OnDisconnected()

virtual void XmobiTea.ProtonNetClient.TcpClient.OnDisconnected ( )
protectedvirtual

Called when the client has successfully disconnected from the server. Can be overridden in derived classes to handle the event.

Reimplemented in XmobiTea.ProtonNet.Client.Socket.Clients.SocketTcpClient, XmobiTea.ProtonNet.Client.Socket.Clients.SocketWsClient, XmobiTea.ProtonNetClient.HttpClient, and XmobiTea.ProtonNetClient.WsClient.

◆ OnDisconnecting()

virtual void XmobiTea.ProtonNetClient.TcpClient.OnDisconnecting ( )
protectedvirtual

Called when the client is in the process of disconnecting. Can be overridden in derived classes to handle the event.

Reimplemented in XmobiTea.ProtonNetClient.WsClient.

◆ OnError()

virtual void XmobiTea.ProtonNetClient.TcpClient.OnError ( SocketError error)
protectedvirtual

Called when an error occurs during socket operations. Can be overridden in derived classes to handle the event.

Parameters
errorThe socket error that occurred.

◆ OnReceived()

virtual void XmobiTea.ProtonNetClient.TcpClient.OnReceived ( byte[] buffer,
int position,
int length )
protectedvirtual

Called when data is received from the server. Can be overridden in derived classes to handle the event.

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

Reimplemented in XmobiTea.ProtonNet.Client.Socket.Clients.SocketTcpClient, XmobiTea.ProtonNetClient.HttpClient, and XmobiTea.ProtonNetClient.WsClient.

◆ OnSent()

virtual void XmobiTea.ProtonNetClient.TcpClient.OnSent ( int sent,
int pending )
protectedvirtual

Called when data is successfully sent to the server. Can be overridden in derived classes to handle the event.

Parameters
sentThe number of bytes sent.
pendingThe number of bytes pending in the send buffer.

◆ Reconnect()

virtual bool XmobiTea.ProtonNetClient.TcpClient.Reconnect ( )
virtual

Reconnects the client to the server by first disconnecting and then reconnecting.

Returns
True if the reconnection is successful; otherwise, false.

Implements XmobiTea.ProtonNetClient.IClient.

Reimplemented in XmobiTea.ProtonNet.Client.Socket.Clients.SocketTcpClient, and XmobiTea.ProtonNet.Client.Socket.Clients.SocketWsClient.

◆ ReconnectAsync()

virtual bool XmobiTea.ProtonNetClient.TcpClient.ReconnectAsync ( )
virtual

Reconnects the client to the server asynchronously by first disconnecting and then reconnecting.

Returns
True if the reconnection is successful; otherwise, false.

Implements XmobiTea.ProtonNetClient.IClient.

◆ Send() [1/2]

virtual int XmobiTea.ProtonNetClient.TcpClient.Send ( byte[] buffer)
virtual

Sends data to the server synchronously.

Parameters
bufferThe data to send.
Returns
The number of bytes sent.

Implements XmobiTea.ProtonNetClient.IClient.

Reimplemented in XmobiTea.ProtonNet.Client.Socket.Clients.SocketWsClient.

◆ Send() [2/2]

virtual int XmobiTea.ProtonNetClient.TcpClient.Send ( byte[] buffer,
int position,
int length )
virtual

Sends data to the server synchronously starting from a specific position in the buffer.

Parameters
bufferThe data to send.
positionThe starting position in the buffer.
lengthThe number of bytes to send.
Returns
The number of bytes sent.

Implements XmobiTea.ProtonNetClient.IClient.

◆ SendAsync() [1/2]

virtual bool XmobiTea.ProtonNetClient.TcpClient.SendAsync ( byte[] buffer)
virtual

Sends data to the server asynchronously.

Parameters
bufferThe data to send.
Returns
True if the data was sent successfully; otherwise, false.

Implements XmobiTea.ProtonNetClient.IClient.

Reimplemented in XmobiTea.ProtonNet.Client.Socket.Clients.SocketWsClient.

◆ SendAsync() [2/2]

virtual bool XmobiTea.ProtonNetClient.TcpClient.SendAsync ( byte[] buffer,
int position,
int length )
virtual

Sends data to the server asynchronously starting from a specific position in the buffer.

Parameters
bufferThe data to send.
positionThe starting position in the buffer.
lengthThe number of bytes to send.
Returns
True if the data was sent successfully; otherwise, false.

Implements XmobiTea.ProtonNetClient.IClient.


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