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

An implement of interface WebSocket. More...

Inheritance diagram for XmobiTea.ProtonNetCommon.WebSocket:
XmobiTea.ProtonNetCommon.IWebSocket

Public Member Functions

 WebSocket (IWebSocket originWs)
 Initializes a new instance of the WebSocket class with the specified origin WebSocket.
 
bool PerformClientUpgrade (HttpResponse response, string id)
 Performs the WebSocket client upgrade.
 
bool PerformServerUpgrade (HttpRequest request, HttpResponse response)
 Performs the WebSocket server upgrade.
 
void PrepareSendFrame (byte opcode, bool mask, byte[] buffer, int position, int length, int status=0)
 Prepares the WebSocket frame to be sent.
 
void PrepareReceiveFrame (byte[] buffer, int position, int length)
 Prepares the WebSocket frame received for processing.
 
void ClearWsBuffers ()
 Clears the WebSocket buffers.
 
void InitWsNonce ()
 Initializes the WebSocket nonce with random bytes.
 
void OnWsConnecting (HttpRequest request)
 Invoked when a WebSocket connection is being established.
 
void OnWsConnected (HttpResponse response)
 Invoked when a WebSocket connection has been successfully established.
 
bool OnWsConnecting (HttpRequest request, HttpResponse response)
 Invoked when a WebSocket connection is being established, allowing to modify the response.
 
void OnWsConnected (HttpRequest request)
 Invoked when a WebSocket connection has been successfully established.
 
void OnWsDisconnecting ()
 Invoked when a WebSocket connection is about to be closed.
 
void OnWsDisconnected ()
 Invoked when a WebSocket connection has been closed.
 
void OnWsReceived (byte[] buffer, int position, int length)
 Invoked when a WebSocket message has been received.
 
void OnWsClose (byte[] buffer, int position, int length, int status=1000)
 Invoked when a WebSocket close frame has been received.
 
void OnWsPing (byte[] buffer, int position, int length)
 Invoked when a WebSocket ping frame has been received.
 
void OnWsPong (byte[] buffer, int position, int length)
 Invoked when a WebSocket pong frame has been received.
 
void OnWsError (string error)
 Invoked when a WebSocket error occurs, providing an error message.
 
void OnWsError (SocketError error)
 Invoked when a WebSocket error occurs, providing a SocketError.
 
void SendUpgrade (HttpResponse response)
 Sends an HTTP response to complete the WebSocket upgrade process.
 
- Public Member Functions inherited from XmobiTea.ProtonNetCommon.IWebSocket

Properties

bool handshaked [get, set]
 Indicates whether the WebSocket handshake has been completed.
 
object sendLock [get]
 The lock object used to synchronize access to the send buffer.
 
IMemoryBuffer sendBuffer [get]
 The buffer used to store the WebSocket frame to be sent.
 
byte[] nonce [get]
 The nonce used during the WebSocket handshake.
 

Detailed Description

An implement of interface WebSocket.

Constructor & Destructor Documentation

◆ WebSocket()

XmobiTea.ProtonNetCommon.WebSocket.WebSocket ( IWebSocket originWs)

Initializes a new instance of the WebSocket class with the specified origin WebSocket.

Parameters
originWsThe origin WebSocket instance.

Member Function Documentation

◆ OnWsClose()

void XmobiTea.ProtonNetCommon.WebSocket.OnWsClose ( byte[] buffer,
int position,
int length,
int status = 1000 )

Invoked when a WebSocket close frame has been received.

Parameters
bufferThe buffer containing the close frame data.
positionThe position in the buffer where the data starts.
lengthThe length of the close frame data.
statusThe close status code.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsConnected() [1/2]

void XmobiTea.ProtonNetCommon.WebSocket.OnWsConnected ( HttpRequest request)

Invoked when a WebSocket connection has been successfully established.

Parameters
requestThe HTTP request initiating the connection.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsConnected() [2/2]

void XmobiTea.ProtonNetCommon.WebSocket.OnWsConnected ( HttpResponse response)

Invoked when a WebSocket connection has been successfully established.

Parameters
responseThe HTTP response confirming the connection.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsConnecting() [1/2]

void XmobiTea.ProtonNetCommon.WebSocket.OnWsConnecting ( HttpRequest request)

Invoked when a WebSocket connection is being established.

Parameters
requestThe HTTP request initiating the connection.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsConnecting() [2/2]

bool XmobiTea.ProtonNetCommon.WebSocket.OnWsConnecting ( HttpRequest request,
HttpResponse response )

Invoked when a WebSocket connection is being established, allowing to modify the response.

Parameters
requestThe HTTP request initiating the connection.
responseThe HTTP response confirming the connection.
Returns
True if the connection should be accepted; otherwise, false.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsDisconnected()

void XmobiTea.ProtonNetCommon.WebSocket.OnWsDisconnected ( )

Invoked when a WebSocket connection has been closed.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsDisconnecting()

void XmobiTea.ProtonNetCommon.WebSocket.OnWsDisconnecting ( )

Invoked when a WebSocket connection is about to be closed.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsError() [1/2]

void XmobiTea.ProtonNetCommon.WebSocket.OnWsError ( SocketError error)

Invoked when a WebSocket error occurs, providing a SocketError.

Parameters
errorThe SocketError that occurred.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsError() [2/2]

void XmobiTea.ProtonNetCommon.WebSocket.OnWsError ( string error)

Invoked when a WebSocket error occurs, providing an error message.

Parameters
errorThe error message.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsPing()

void XmobiTea.ProtonNetCommon.WebSocket.OnWsPing ( byte[] buffer,
int position,
int length )

Invoked when a WebSocket ping frame has been received.

Parameters
bufferThe buffer containing the ping frame data.
positionThe position in the buffer where the data starts.
lengthThe length of the ping frame data.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsPong()

void XmobiTea.ProtonNetCommon.WebSocket.OnWsPong ( byte[] buffer,
int position,
int length )

Invoked when a WebSocket pong frame has been received.

Parameters
bufferThe buffer containing the pong frame data.
positionThe position in the buffer where the data starts.
lengthThe length of the pong frame data.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsReceived()

void XmobiTea.ProtonNetCommon.WebSocket.OnWsReceived ( byte[] buffer,
int position,
int length )

Invoked when a WebSocket message has been received.

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

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ PerformClientUpgrade()

bool XmobiTea.ProtonNetCommon.WebSocket.PerformClientUpgrade ( HttpResponse response,
string id )

Performs the WebSocket client upgrade.

Parameters
responseThe HTTP response for the upgrade.
idThe WebSocket ID.
Returns
True if the upgrade was successful, otherwise false.

◆ PerformServerUpgrade()

bool XmobiTea.ProtonNetCommon.WebSocket.PerformServerUpgrade ( HttpRequest request,
HttpResponse response )

Performs the WebSocket server upgrade.

Parameters
requestThe HTTP request initiating the upgrade.
responseThe HTTP response for the upgrade.
Returns
True if the upgrade was successful, otherwise false.

◆ PrepareReceiveFrame()

void XmobiTea.ProtonNetCommon.WebSocket.PrepareReceiveFrame ( byte[] buffer,
int position,
int length )

Prepares the WebSocket frame received for processing.

Parameters
bufferThe buffer containing the received frame.
positionThe position in the buffer where the data starts.
lengthThe length of the received data.

◆ PrepareSendFrame()

void XmobiTea.ProtonNetCommon.WebSocket.PrepareSendFrame ( byte opcode,
bool mask,
byte[] buffer,
int position,
int length,
int status = 0 )

Prepares the WebSocket frame to be sent.

Parameters
opcodeThe operation code of the WebSocket frame.
maskIndicates whether the frame should be masked.
bufferThe buffer containing the data to be sent.
positionThe position in the buffer where the data starts.
lengthThe length of the data to be sent.
statusThe status code for the frame, if applicable.

◆ SendUpgrade()

void XmobiTea.ProtonNetCommon.WebSocket.SendUpgrade ( HttpResponse response)

Sends an HTTP response to complete the WebSocket upgrade process.

Parameters
responseThe HTTP response to be sent.

Implements XmobiTea.ProtonNetCommon.IWebSocket.


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