ProtonNet Server 1.0
An Open Solution for all your socket or web api needs.
|
Implements a WebSocket client over an HTTP connection. Supports both synchronous and asynchronous operations. More...
Public Member Functions | |
WsClient(string address, int port, TcpClientOptions options) override bool | Connect () |
Initializes a new instance of the WsClient class. | |
override bool | ConnectAsync () |
Establishes an asynchronous connection to the WebSocket server. | |
int | SendText (byte[] buffer) |
Sends a text message synchronously to the server. | |
int | SendText (byte[] buffer, int position, int length) |
Sends a text message synchronously to the server. | |
bool | SendTextAsync (byte[] buffer) |
Sends a text message asynchronously to the server. | |
bool | SendTextAsync (byte[] buffer, int position, int length) |
Sends a text message asynchronously to the server. | |
int | SendBinary (byte[] buffer) |
Sends a binary message synchronously to the server. | |
int | SendBinary (byte[] buffer, int position, int length) |
Sends a binary message synchronously to the server. | |
bool | SendBinaryAsync (byte[] buffer) |
Sends a binary message asynchronously to the server. | |
bool | SendBinaryAsync (byte[] buffer, int position, int length) |
Sends a binary message asynchronously to the server. | |
int | SendClose (int status, byte[] buffer) |
Sends a close frame with a status code synchronously to the server. | |
int | SendClose (int status, byte[] buffer, int position, int length) |
Sends a close frame with a status code synchronously to the server. | |
bool | SendCloseAsync (int status, byte[] buffer) |
Sends a close frame with a status code asynchronously to the server. | |
bool | SendCloseAsync (int status, byte[] buffer, int position, int length) |
Sends a close frame with a status code asynchronously to the server. | |
int | SendPing (byte[] buffer) |
Sends a ping frame synchronously to the server. | |
int | SendPing (byte[] buffer, int position, int length) |
Sends a ping frame synchronously to the server. | |
bool | SendPingAsync (byte[] buffer) |
Sends a ping frame asynchronously to the server. | |
bool | SendPingAsync (byte[] buffer, int position, int length) |
Sends a ping frame asynchronously to the server. | |
int | SendPong (byte[] buffer) |
Sends a pong frame synchronously to the server. | |
int | SendPong (byte[] buffer, int position, int length) |
Sends a pong frame synchronously to the server. | |
bool | SendPongAsync (byte[] buffer) |
Sends a pong frame asynchronously to the server. | |
bool | SendPongAsync (byte[] buffer, int position, int length) |
Sends a pong frame asynchronously to the server. | |
virtual void | OnWsConnecting (HttpRequest request) |
Prepares the WebSocket connection by setting the necessary headers. | |
virtual void | OnWsConnected (HttpResponse response) |
Called when the WebSocket connection is successfully established. | |
virtual void | OnWsConnected (HttpRequest request) |
Called when the WebSocket connection is successfully established. | |
virtual bool | OnWsConnecting (HttpRequest request, HttpResponse response) |
OnWsConnecting. | |
virtual void | OnWsDisconnecting () |
Called when the WebSocket connection is in the process of disconnecting. | |
virtual void | OnWsDisconnected () |
Called when the WebSocket connection is successfully disconnected. | |
virtual void | OnWsReceived (byte[] buffer, int position, int length) |
Processes the WebSocket frames received from the server. | |
virtual void | OnWsClose (byte[] buffer, int position, int length, int status=1000) |
Handles a close frame received from the server. | |
virtual void | OnWsPing (byte[] buffer, int position, int length) |
Handles a ping frame received from the server by sending a pong frame. | |
virtual void | OnWsPong (byte[] buffer, int position, int length) |
Handles a pong frame received from the server. | |
virtual void | OnWsError (string error) |
Handles a WebSocket error by reporting it to the client. | |
virtual void | OnWsError (SocketError error) |
Handles a WebSocket error by reporting it to the client. | |
void | SendUpgrade (HttpResponse response) |
Upgrades the HTTP connection to a WebSocket connection. | |
Public Member Functions inherited from XmobiTea.ProtonNetClient.HttpClient | |
HttpClient (string address, int port, TcpClientOptions options) | |
Initializes a new instance of the HttpClient class. | |
int | SendRequest (HttpRequest request) |
Sends an HTTP request synchronously using the provided request data. | |
bool | SendRequestAsync (HttpRequest request) |
Sends an HTTP request asynchronously using the provided request data. | |
Public Member Functions inherited from XmobiTea.ProtonNetClient.TcpClient | |
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 | 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 | 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 | |
Public Member Functions inherited from XmobiTea.ProtonNetClient.IHttpClient | |
Public Member Functions inherited from XmobiTea.ProtonNetCommon.IWebSocket | |
Public Member Functions inherited from XmobiTea.ProtonNetClient.IWsClient |
Protected Member Functions | |
override void | OnConnected () |
Called when the client has successfully connected to the server. | |
override void | OnDisconnecting () |
Called when the client is in the process of disconnecting. | |
override void | OnDisconnected () |
Called when the client has successfully disconnected from the server. | |
override void | OnReceived (byte[] buffer, int position, int length) |
Processes the data received from the server. | |
override void | OnReceivedResponseHeader (HttpResponse response) |
Processes the response header received from the server. | |
override void | OnReceivedResponse (HttpResponse response) |
Processes the response body received from the server. | |
override void | OnReceivedResponseError (HttpResponse response, string error) |
Handles errors in the response received from the server. | |
Protected Member Functions inherited from XmobiTea.ProtonNetClient.HttpClient | |
Protected Member Functions inherited from XmobiTea.ProtonNetClient.TcpClient | |
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 | 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. | |
Additional Inherited Members | |
Properties inherited from XmobiTea.ProtonNetClient.HttpClient | |
HttpRequest | Request [get] |
Gets the current HTTP request being processed by the client. | |
HttpResponse | Response [get] |
Gets the current HTTP response received from the server. | |
Properties inherited from XmobiTea.ProtonNetClient.TcpClient | |
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. | |
Implements a WebSocket client over an HTTP connection. Supports both synchronous and asynchronous operations.
|
virtual |
Initializes a new instance of the WsClient class.
address | The server address to connect to. |
port | The port number on the server. |
options | TCP client options for configuring the connection. |
Establishes a synchronous connection to the WebSocket server.
Reimplemented from XmobiTea.ProtonNetClient.TcpClient.
|
virtual |
Establishes an asynchronous connection to the WebSocket server.
Reimplemented from XmobiTea.ProtonNetClient.TcpClient.
|
protectedvirtual |
Called when the client has successfully connected to the server.
Reimplemented from XmobiTea.ProtonNetClient.TcpClient.
|
protectedvirtual |
Called when the client has successfully disconnected from the server.
Reimplemented from XmobiTea.ProtonNetClient.HttpClient.
|
protectedvirtual |
Called when the client is in the process of disconnecting.
Reimplemented from XmobiTea.ProtonNetClient.TcpClient.
|
protectedvirtual |
Processes the data received from the server.
buffer | The buffer containing the received data. |
position | The starting position in the buffer. |
length | The length of the received data. |
Reimplemented from XmobiTea.ProtonNetClient.HttpClient.
|
protectedvirtual |
Processes the response body received from the server.
response | The HTTP response received. |
Reimplemented from XmobiTea.ProtonNetClient.HttpClient.
|
protectedvirtual |
Handles errors in the response received from the server.
response | The HTTP response that caused the error. |
error | The error message. |
Reimplemented from XmobiTea.ProtonNetClient.HttpClient.
|
protectedvirtual |
Processes the response header received from the server.
response | The HTTP response received. |
Reimplemented from XmobiTea.ProtonNetClient.HttpClient.
|
virtual |
Handles a close frame received from the server.
buffer | The buffer containing the close frame. |
position | The starting position in the buffer. |
length | The length of the close frame. |
status | The close status code. |
Implements XmobiTea.ProtonNetCommon.IWebSocket.
|
virtual |
Called when the WebSocket connection is successfully established.
request | The HTTP request that initiated the WebSocket connection. |
Implements XmobiTea.ProtonNetCommon.IWebSocket.
|
virtual |
Called when the WebSocket connection is successfully established.
response | The HTTP response that confirms the WebSocket upgrade. |
Implements XmobiTea.ProtonNetCommon.IWebSocket.
Reimplemented in XmobiTea.ProtonNet.Client.Socket.Clients.SocketWsClient.
|
virtual |
Prepares the WebSocket connection by setting the necessary headers.
request | The HTTP request being sent to initiate the WebSocket connection. |
Implements XmobiTea.ProtonNetCommon.IWebSocket.
|
virtual |
OnWsConnecting.
request | The HTTP request that initiated the WebSocket connection. |
response | The HTTP response that initiated the WebSocket connection. |
Implements XmobiTea.ProtonNetCommon.IWebSocket.
|
virtual |
Called when the WebSocket connection is successfully disconnected.
Implements XmobiTea.ProtonNetCommon.IWebSocket.
|
virtual |
Called when the WebSocket connection is in the process of disconnecting.
Implements XmobiTea.ProtonNetCommon.IWebSocket.
|
virtual |
Handles a WebSocket error by reporting it to the client.
error | The socket error. |
Implements XmobiTea.ProtonNetCommon.IWebSocket.
|
virtual |
Handles a WebSocket error by reporting it to the client.
error | The error message. |
Implements XmobiTea.ProtonNetCommon.IWebSocket.
|
virtual |
Handles a ping frame received from the server by sending a pong frame.
buffer | The buffer containing the ping frame. |
position | The starting position in the buffer. |
length | The length of the ping frame. |
Implements XmobiTea.ProtonNetCommon.IWebSocket.
|
virtual |
Handles a pong frame received from the server.
buffer | The buffer containing the pong frame. |
position | The starting position in the buffer. |
length | The length of the pong frame. |
Implements XmobiTea.ProtonNetCommon.IWebSocket.
|
virtual |
Processes the WebSocket frames received from the server.
buffer | The buffer containing the received data. |
position | The starting position in the buffer. |
length | The length of the received data. |
Implements XmobiTea.ProtonNetCommon.IWebSocket.
Reimplemented in XmobiTea.ProtonNet.Client.Socket.Clients.SocketWsClient.
int XmobiTea.ProtonNetClient.WsClient.SendBinary | ( | byte[] | buffer | ) |
Sends a binary message synchronously to the server.
buffer | The byte array containing the binary message. |
Implements XmobiTea.ProtonNetClient.IWsClient.
int XmobiTea.ProtonNetClient.WsClient.SendBinary | ( | byte[] | buffer, |
int | position, | ||
int | length ) |
Sends a binary message synchronously to the server.
buffer | The byte array containing the binary message. |
position | The starting position in the buffer. |
length | The number of bytes to send. |
Implements XmobiTea.ProtonNetClient.IWsClient.
bool XmobiTea.ProtonNetClient.WsClient.SendBinaryAsync | ( | byte[] | buffer | ) |
Sends a binary message asynchronously to the server.
buffer | The byte array containing the binary message. |
Implements XmobiTea.ProtonNetClient.IWsClient.
bool XmobiTea.ProtonNetClient.WsClient.SendBinaryAsync | ( | byte[] | buffer, |
int | position, | ||
int | length ) |
Sends a binary message asynchronously to the server.
buffer | The byte array containing the binary message. |
position | The starting position in the buffer. |
length | The number of bytes to send. |
Implements XmobiTea.ProtonNetClient.IWsClient.
int XmobiTea.ProtonNetClient.WsClient.SendClose | ( | int | status, |
byte[] | buffer ) |
Sends a close frame with a status code synchronously to the server.
status | The close status code. |
buffer | The byte array containing the close message. |
Implements XmobiTea.ProtonNetClient.IWsClient.
int XmobiTea.ProtonNetClient.WsClient.SendClose | ( | int | status, |
byte[] | buffer, | ||
int | position, | ||
int | length ) |
Sends a close frame with a status code synchronously to the server.
status | The close status code. |
buffer | The byte array containing the close message. |
position | The starting position in the buffer. |
length | The number of bytes to send. |
Implements XmobiTea.ProtonNetClient.IWsClient.
bool XmobiTea.ProtonNetClient.WsClient.SendCloseAsync | ( | int | status, |
byte[] | buffer ) |
Sends a close frame with a status code asynchronously to the server.
status | The close status code. |
buffer | The byte array containing the close message. |
Implements XmobiTea.ProtonNetClient.IWsClient.
bool XmobiTea.ProtonNetClient.WsClient.SendCloseAsync | ( | int | status, |
byte[] | buffer, | ||
int | position, | ||
int | length ) |
Sends a close frame with a status code asynchronously to the server.
status | The close status code. |
buffer | The byte array containing the close message. |
position | The starting position in the buffer. |
length | The number of bytes to send. |
Implements XmobiTea.ProtonNetClient.IWsClient.
int XmobiTea.ProtonNetClient.WsClient.SendPing | ( | byte[] | buffer | ) |
Sends a ping frame synchronously to the server.
buffer | The byte array containing the ping message. |
Implements XmobiTea.ProtonNetClient.IWsClient.
int XmobiTea.ProtonNetClient.WsClient.SendPing | ( | byte[] | buffer, |
int | position, | ||
int | length ) |
Sends a ping frame synchronously to the server.
buffer | The byte array containing the ping message. |
position | The starting position in the buffer. |
length | The number of bytes to send. |
Implements XmobiTea.ProtonNetClient.IWsClient.
bool XmobiTea.ProtonNetClient.WsClient.SendPingAsync | ( | byte[] | buffer | ) |
Sends a ping frame asynchronously to the server.
buffer | The byte array containing the ping message. |
Implements XmobiTea.ProtonNetClient.IWsClient.
bool XmobiTea.ProtonNetClient.WsClient.SendPingAsync | ( | byte[] | buffer, |
int | position, | ||
int | length ) |
Sends a ping frame asynchronously to the server.
buffer | The byte array containing the ping message. |
position | The starting position in the buffer. |
length | The number of bytes to send. |
Implements XmobiTea.ProtonNetClient.IWsClient.
int XmobiTea.ProtonNetClient.WsClient.SendPong | ( | byte[] | buffer | ) |
Sends a pong frame synchronously to the server.
buffer | The byte array containing the pong message. |
Implements XmobiTea.ProtonNetClient.IWsClient.
int XmobiTea.ProtonNetClient.WsClient.SendPong | ( | byte[] | buffer, |
int | position, | ||
int | length ) |
Sends a pong frame synchronously to the server.
buffer | The byte array containing the pong message. |
position | The starting position in the buffer. |
length | The number of bytes to send. |
Implements XmobiTea.ProtonNetClient.IWsClient.
bool XmobiTea.ProtonNetClient.WsClient.SendPongAsync | ( | byte[] | buffer | ) |
Sends a pong frame asynchronously to the server.
buffer | The byte array containing the pong message. |
Implements XmobiTea.ProtonNetClient.IWsClient.
bool XmobiTea.ProtonNetClient.WsClient.SendPongAsync | ( | byte[] | buffer, |
int | position, | ||
int | length ) |
Sends a pong frame asynchronously to the server.
buffer | The byte array containing the pong message. |
position | The starting position in the buffer. |
length | The number of bytes to send. |
Implements XmobiTea.ProtonNetClient.IWsClient.
int XmobiTea.ProtonNetClient.WsClient.SendText | ( | byte[] | buffer | ) |
Sends a text message synchronously to the server.
buffer | The byte array containing the text message. |
Implements XmobiTea.ProtonNetClient.IWsClient.
int XmobiTea.ProtonNetClient.WsClient.SendText | ( | byte[] | buffer, |
int | position, | ||
int | length ) |
Sends a text message synchronously to the server.
buffer | The byte array containing the text message. |
position | The starting position in the buffer. |
length | The number of bytes to send. |
Implements XmobiTea.ProtonNetClient.IWsClient.
bool XmobiTea.ProtonNetClient.WsClient.SendTextAsync | ( | byte[] | buffer | ) |
Sends a text message asynchronously to the server.
buffer | The byte array containing the text message. |
Implements XmobiTea.ProtonNetClient.IWsClient.
bool XmobiTea.ProtonNetClient.WsClient.SendTextAsync | ( | byte[] | buffer, |
int | position, | ||
int | length ) |
Sends a text message asynchronously to the server.
buffer | The byte array containing the text message. |
position | The starting position in the buffer. |
length | The number of bytes to send. |
Implements XmobiTea.ProtonNetClient.IWsClient.
void XmobiTea.ProtonNetClient.WsClient.SendUpgrade | ( | HttpResponse | response | ) |
Upgrades the HTTP connection to a WebSocket connection.
response | The HTTP response confirming the upgrade. |
Implements XmobiTea.ProtonNetCommon.IWebSocket.