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

Represents a WebSocket session that inherits from HttpSession and implements WebSocket functionality. More...

Inheritance diagram for XmobiTea.ProtonNetServer.WsSession:
XmobiTea.ProtonNetServer.HttpSession XmobiTea.ProtonNetCommon.IWebSocket XmobiTea.ProtonNetServer.IWsSession XmobiTea.ProtonNetServer.TcpSession XmobiTea.ProtonNetServer.IHttpSession XmobiTea.ProtonNetServer.ISession XmobiTea.ProtonNetServer.ITcpSession XmobiTea.ProtonNetServer.ISession XmobiTea.ProtonNetServer.ISession XmobiTea.ProtonNet.Server.Socket.Sessions.SocketWsSession

Public Member Functions

WsSession(WsServer server) int SendText (byte[] buffer)
 Initializes a new instance of the WsSession class with the specified WebSocket server.
 
int SendText (byte[] buffer, int position, int length)
 Sends a text message synchronously to the WebSocket connection with a specified position and length.
 
bool SendTextAsync (byte[] buffer)
 Sends a text message asynchronously to the WebSocket connection.
 
bool SendTextAsync (byte[] buffer, int position, int length)
 Sends a text message asynchronously to the WebSocket connection with a specified position and length.
 
int SendBinary (byte[] buffer)
 Sends a binary message synchronously to the WebSocket connection.
 
int SendBinary (byte[] buffer, int position, int length)
 Sends a binary message synchronously to the WebSocket connection with a specified position and length.
 
bool SendBinaryAsync (byte[] buffer)
 Sends a binary message asynchronously to the WebSocket connection.
 
bool SendBinaryAsync (byte[] buffer, int position, int length)
 Sends a binary message asynchronously to the WebSocket connection with a specified position and length.
 
int SendClose (int status, byte[] buffer)
 Sends a close frame synchronously to the WebSocket connection with the specified status code and buffer.
 
int SendClose (int status, byte[] buffer, int position, int length)
 Sends a close frame synchronously to the WebSocket connection with the specified status code, buffer, position, and length.
 
bool SendCloseAsync (int status, byte[] buffer)
 Sends a close frame asynchronously to the WebSocket connection with the specified status code and buffer.
 
bool SendCloseAsync (int status, byte[] buffer, int position, int length)
 Sends a close frame asynchronously to the WebSocket connection with the specified status code, buffer, position, and length.
 
int SendPing (byte[] buffer)
 Sends a ping frame synchronously to the WebSocket connection.
 
int SendPing (byte[] buffer, int position, int length)
 Sends a ping frame synchronously to the WebSocket connection with a specified position and length.
 
bool SendPingAsync (byte[] buffer)
 Sends a ping frame asynchronously to the WebSocket connection.
 
bool SendPingAsync (byte[] buffer, int position, int length)
 Sends a ping frame asynchronously to the WebSocket connection with a specified position and length.
 
int SendPong (byte[] buffer)
 Sends a pong frame synchronously to the WebSocket connection.
 
int SendPong (byte[] buffer, int position, int length)
 Sends a pong frame synchronously to the WebSocket connection with a specified position and length.
 
bool SendPongAsync (byte[] buffer)
 Sends a pong frame asynchronously to the WebSocket connection.
 
bool SendPongAsync (byte[] buffer, int position, int length)
 Sends a pong frame asynchronously to the WebSocket connection with a specified position and length.
 
virtual void OnWsConnecting (HttpRequest request)
 Called when a WebSocket connection is being established.
 
virtual void OnWsConnected (HttpResponse response)
 Called when a WebSocket connection is successfully established.
 
virtual bool OnWsConnecting (HttpRequest request, HttpResponse response)
 Called when a WebSocket connection is being established.
 
virtual void OnWsConnected (HttpRequest request)
 Called when a WebSocket connection is successfully established.
 
virtual void OnWsDisconnecting ()
 Called when a WebSocket connection is being disconnected.
 
virtual void OnWsDisconnected ()
 Called when a WebSocket connection is successfully disconnected.
 
virtual void OnWsReceived (byte[] buffer, int position, int length)
 Called when data is received from the WebSocket connection.
 
virtual void OnWsClose (byte[] buffer, int position, int length, int status=1000)
 Called when a WebSocket connection is closed.
 
virtual void OnWsPing (byte[] buffer, int position, int length)
 Called when a WebSocket ping is received.
 
virtual void OnWsPong (byte[] buffer, int position, int length)
 Called when a WebSocket pong is received.
 
virtual void OnWsError (string error)
 Called when a WebSocket error occurs with a custom error message.
 
virtual void OnWsError (SocketError error)
 Called when a WebSocket error occurs with a SocketError instance.
 
void SendUpgrade (HttpResponse response)
 Sends a WebSocket upgrade response to the client.
 
- Public Member Functions inherited from XmobiTea.ProtonNetServer.HttpSession
 HttpSession (HttpServer server)
 Initializes a new instance of the HttpSession class.
 
virtual int SendResponse (HttpResponse response)
 Sends an HTTP response synchronously.
 
virtual bool SendResponseAsync (HttpResponse response)
 Sends an HTTP response asynchronously.
 
- Public Member Functions inherited from XmobiTea.ProtonNetServer.TcpSession
 TcpSession (TcpServer server)
 Initializes a new instance of the TcpSession class.
 
INetworkStatistics GetNetworkStatistics ()
 Gets the network statistics for this session.
 
virtual bool Disconnect ()
 Disconnects the session.
 
virtual int Send (byte[] buffer)
 Sends data synchronously.
 
virtual int Send (byte[] buffer, int position, int length)
 Sends data synchronously with the specified position and length.
 
virtual bool SendAsync (byte[] buffer)
 Sends data asynchronously.
 
virtual bool SendAsync (byte[] buffer, int position, int length)
 Sends data asynchronously with the specified position and length.
 
void Dispose ()
 Releases all resources used by the current instance of the TcpSession class.
 
- Public Member Functions inherited from XmobiTea.ProtonNetServer.ISession
- Public Member Functions inherited from XmobiTea.ProtonNetServer.IHttpSession
- Public Member Functions inherited from XmobiTea.ProtonNetCommon.IWebSocket
- Public Member Functions inherited from XmobiTea.ProtonNetServer.IWsSession

Protected Member Functions

override void OnDisconnecting ()
 Called when the session is disconnecting.
 
override void OnDisconnected ()
 Called when the session has been disconnected.
 
override void OnReceived (byte[] buffer, int position, int length)
 Called when data is received from the connection.
 
override void OnReceivedRequestHeader (HttpRequest request)
 Called when the HTTP request headers are received.
 
override void OnReceivedRequest (HttpRequest request)
 Called when the complete HTTP request is received.
 
override void OnReceivedRequestError (HttpRequest request, string error)
 Called when an error occurs while receiving the HTTP request.
 
- Protected Member Functions inherited from XmobiTea.ProtonNetServer.HttpSession
- Protected Member Functions inherited from XmobiTea.ProtonNetServer.TcpSession
virtual void OnConnecting ()
 Invoked when the session is in the process of connecting.
 
virtual void OnConnected ()
 Invoked when the session has successfully connected.
 
virtual void OnSent (int sent, int pending)
 Invoked when data is successfully sent to the remote endpoint.
 
virtual void OnEmpty ()
 Invoked when the send buffer is empty.
 
virtual void OnError (SocketError error)
 Invoked when an error occurs during the session operation.
 
virtual void Dispose (bool disposingManagedResources)
 Releases the unmanaged resources used by the TcpSession and optionally releases the managed resources.
 

Additional Inherited Members

- Package Functions inherited from XmobiTea.ProtonNetServer.TcpSession
- Properties inherited from XmobiTea.ProtonNetServer.HttpSession
HttpRequest Request [get]
 Gets the current HTTP request being processed.
 
HttpResponse Response [get]
 Gets the current HTTP response being processed.
 
- Properties inherited from XmobiTea.ProtonNetServer.TcpSession
string Id [get]
 Gets the unique identifier for this session.
 
TcpServer Server [get]
 Gets the server that owns this session.
 
Socket Socket [get]
 Gets the socket associated with this session.
 
bool IsConnected [get]
 Gets a value indicating whether the session is currently connected.
 
bool IsDisposed [get]
 Gets a value indicating whether the session has been disposed.
 
bool IsSocketDisposed [get]
 Gets a value indicating whether the socket has been disposed.
 
TcpServerOptions Options [get]
 Gets the options for the TCP server.
 

Detailed Description

Represents a WebSocket session that inherits from HttpSession and implements WebSocket functionality.

Member Function Documentation

◆ OnDisconnected()

override void XmobiTea.ProtonNetServer.WsSession.OnDisconnected ( )
protectedvirtual

Called when the session has been disconnected.

Reimplemented from XmobiTea.ProtonNetServer.HttpSession.

◆ OnDisconnecting()

override void XmobiTea.ProtonNetServer.WsSession.OnDisconnecting ( )
protectedvirtual

Called when the session is disconnecting.

Reimplemented from XmobiTea.ProtonNetServer.TcpSession.

◆ OnReceived()

override void XmobiTea.ProtonNetServer.WsSession.OnReceived ( byte[] buffer,
int position,
int length )
protectedvirtual

Called when data is received from the connection.

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

Reimplemented from XmobiTea.ProtonNetServer.HttpSession.

◆ OnReceivedRequest()

override void XmobiTea.ProtonNetServer.WsSession.OnReceivedRequest ( HttpRequest request)
protectedvirtual

Called when the complete HTTP request is received.

Parameters
requestThe received HTTP request.

Reimplemented from XmobiTea.ProtonNetServer.HttpSession.

◆ OnReceivedRequestError()

override void XmobiTea.ProtonNetServer.WsSession.OnReceivedRequestError ( HttpRequest request,
string error )
protectedvirtual

Called when an error occurs while receiving the HTTP request.

Parameters
requestThe HTTP request that caused the error.
errorThe error message.

Reimplemented from XmobiTea.ProtonNetServer.HttpSession.

◆ OnReceivedRequestHeader()

override void XmobiTea.ProtonNetServer.WsSession.OnReceivedRequestHeader ( HttpRequest request)
protectedvirtual

Called when the HTTP request headers are received.

Parameters
requestThe HTTP request containing the headers.

Reimplemented from XmobiTea.ProtonNetServer.HttpSession.

◆ OnWsClose()

virtual void XmobiTea.ProtonNetServer.WsSession.OnWsClose ( byte[] buffer,
int position,
int length,
int status = 1000 )
virtual

Called when a WebSocket connection is closed.

Parameters
bufferThe close data buffer.
positionThe starting position in the buffer.
lengthThe length of the close data.
statusThe close status code.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsConnected() [1/2]

virtual void XmobiTea.ProtonNetServer.WsSession.OnWsConnected ( HttpRequest request)
virtual

Called when a WebSocket connection is successfully established.

Parameters
requestThe HTTP request for the WebSocket connection.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

Reimplemented in XmobiTea.ProtonNet.Server.Socket.Sessions.SocketWsSession.

◆ OnWsConnected() [2/2]

virtual void XmobiTea.ProtonNetServer.WsSession.OnWsConnected ( HttpResponse response)
virtual

Called when a WebSocket connection is successfully established.

Parameters
responseThe HTTP response for the WebSocket connection.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsConnecting() [1/2]

virtual void XmobiTea.ProtonNetServer.WsSession.OnWsConnecting ( HttpRequest request)
virtual

Called when a WebSocket connection is being established.

Parameters
requestThe HTTP request for the WebSocket connection.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsConnecting() [2/2]

virtual bool XmobiTea.ProtonNetServer.WsSession.OnWsConnecting ( HttpRequest request,
HttpResponse response )
virtual

Called when a WebSocket connection is being established.

Parameters
requestThe HTTP request for the WebSocket connection.
responseThe HTTP response for the WebSocket connection.
Returns
True if the connection is allowed; otherwise, false.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsDisconnected()

virtual void XmobiTea.ProtonNetServer.WsSession.OnWsDisconnected ( )
virtual

Called when a WebSocket connection is successfully disconnected.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

Reimplemented in XmobiTea.ProtonNet.Server.Socket.Sessions.SocketWsSession.

◆ OnWsDisconnecting()

virtual void XmobiTea.ProtonNetServer.WsSession.OnWsDisconnecting ( )
virtual

Called when a WebSocket connection is being disconnected.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsError() [1/2]

virtual void XmobiTea.ProtonNetServer.WsSession.OnWsError ( SocketError error)
virtual

Called when a WebSocket error occurs with a SocketError instance.

Parameters
errorThe SocketError that occurred.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsError() [2/2]

virtual void XmobiTea.ProtonNetServer.WsSession.OnWsError ( string error)
virtual

Called when a WebSocket error occurs with a custom error message.

Parameters
errorThe error message.

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsPing()

virtual void XmobiTea.ProtonNetServer.WsSession.OnWsPing ( byte[] buffer,
int position,
int length )
virtual

Called when a WebSocket ping is received.

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

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsPong()

virtual void XmobiTea.ProtonNetServer.WsSession.OnWsPong ( byte[] buffer,
int position,
int length )
virtual

Called when a WebSocket pong is received.

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

Implements XmobiTea.ProtonNetCommon.IWebSocket.

◆ OnWsReceived()

virtual void XmobiTea.ProtonNetServer.WsSession.OnWsReceived ( byte[] buffer,
int position,
int length )
virtual

Called when data is received from the WebSocket connection.

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

Implements XmobiTea.ProtonNetCommon.IWebSocket.

Reimplemented in XmobiTea.ProtonNet.Server.Socket.Sessions.SocketWsSession.

◆ SendBinary() [1/2]

int XmobiTea.ProtonNetServer.WsSession.SendBinary ( byte[] buffer)

Sends a binary message synchronously to the WebSocket connection.

Parameters
bufferThe buffer containing the binary message.
Returns
The number of bytes sent.

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendBinary() [2/2]

int XmobiTea.ProtonNetServer.WsSession.SendBinary ( byte[] buffer,
int position,
int length )

Sends a binary message synchronously to the WebSocket connection with a specified position and length.

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

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendBinaryAsync() [1/2]

bool XmobiTea.ProtonNetServer.WsSession.SendBinaryAsync ( byte[] buffer)

Sends a binary message asynchronously to the WebSocket connection.

Parameters
bufferThe buffer containing the binary message.
Returns
True if the message was sent successfully; otherwise, false.

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendBinaryAsync() [2/2]

bool XmobiTea.ProtonNetServer.WsSession.SendBinaryAsync ( byte[] buffer,
int position,
int length )

Sends a binary message asynchronously to the WebSocket connection with a specified position and length.

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

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendClose() [1/2]

int XmobiTea.ProtonNetServer.WsSession.SendClose ( int status,
byte[] buffer )

Sends a close frame synchronously to the WebSocket connection with the specified status code and buffer.

Parameters
statusThe close status code.
bufferThe buffer containing additional data to send with the close frame.
Returns
The number of bytes sent.

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendClose() [2/2]

int XmobiTea.ProtonNetServer.WsSession.SendClose ( int status,
byte[] buffer,
int position,
int length )

Sends a close frame synchronously to the WebSocket connection with the specified status code, buffer, position, and length.

Parameters
statusThe close status code.
bufferThe buffer containing additional data to send with the close frame.
positionThe starting position in the buffer.
lengthThe length of the data to send.
Returns
The number of bytes sent.

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendCloseAsync() [1/2]

bool XmobiTea.ProtonNetServer.WsSession.SendCloseAsync ( int status,
byte[] buffer )

Sends a close frame asynchronously to the WebSocket connection with the specified status code and buffer.

Parameters
statusThe close status code.
bufferThe buffer containing additional data to send with the close frame.
Returns
True if the close frame was sent successfully; otherwise, false.

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendCloseAsync() [2/2]

bool XmobiTea.ProtonNetServer.WsSession.SendCloseAsync ( int status,
byte[] buffer,
int position,
int length )

Sends a close frame asynchronously to the WebSocket connection with the specified status code, buffer, position, and length.

Parameters
statusThe close status code.
bufferThe buffer containing additional data to send with the close frame.
positionThe starting position in the buffer.
lengthThe length of the data to send.
Returns
True if the close frame was sent successfully; otherwise, false.

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendPing() [1/2]

int XmobiTea.ProtonNetServer.WsSession.SendPing ( byte[] buffer)

Sends a ping frame synchronously to the WebSocket connection.

Parameters
bufferThe buffer containing the ping frame.
Returns
The number of bytes sent.

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendPing() [2/2]

int XmobiTea.ProtonNetServer.WsSession.SendPing ( byte[] buffer,
int position,
int length )

Sends a ping frame synchronously to the WebSocket connection with a specified position and length.

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

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendPingAsync() [1/2]

bool XmobiTea.ProtonNetServer.WsSession.SendPingAsync ( byte[] buffer)

Sends a ping frame asynchronously to the WebSocket connection.

Parameters
bufferThe buffer containing the ping frame.
Returns
True if the ping frame was sent successfully; otherwise, false.

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendPingAsync() [2/2]

bool XmobiTea.ProtonNetServer.WsSession.SendPingAsync ( byte[] buffer,
int position,
int length )

Sends a ping frame asynchronously to the WebSocket connection with a specified position and length.

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

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendPong() [1/2]

int XmobiTea.ProtonNetServer.WsSession.SendPong ( byte[] buffer)

Sends a pong frame synchronously to the WebSocket connection.

Parameters
bufferThe buffer containing the pong frame.
Returns
The number of bytes sent.

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendPong() [2/2]

int XmobiTea.ProtonNetServer.WsSession.SendPong ( byte[] buffer,
int position,
int length )

Sends a pong frame synchronously to the WebSocket connection with a specified position and length.

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

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendPongAsync() [1/2]

bool XmobiTea.ProtonNetServer.WsSession.SendPongAsync ( byte[] buffer)

Sends a pong frame asynchronously to the WebSocket connection.

Parameters
bufferThe buffer containing the pong frame.
Returns
True if the pong frame was sent successfully; otherwise, false.

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendPongAsync() [2/2]

bool XmobiTea.ProtonNetServer.WsSession.SendPongAsync ( byte[] buffer,
int position,
int length )

Sends a pong frame asynchronously to the WebSocket connection with a specified position and length.

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

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendText() [1/2]

WsSession(WsServer server) int XmobiTea.ProtonNetServer.WsSession.SendText ( byte[] buffer)

Initializes a new instance of the WsSession class with the specified WebSocket server.

Parameters
serverThe WebSocket server.

Sends a text message synchronously to the WebSocket connection.

Parameters
bufferThe buffer containing the text message.
Returns
The number of bytes sent.

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendText() [2/2]

int XmobiTea.ProtonNetServer.WsSession.SendText ( byte[] buffer,
int position,
int length )

Sends a text message synchronously to the WebSocket connection with a specified position and length.

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

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendTextAsync() [1/2]

bool XmobiTea.ProtonNetServer.WsSession.SendTextAsync ( byte[] buffer)

Sends a text message asynchronously to the WebSocket connection.

Parameters
bufferThe buffer containing the text message.
Returns
True if the message was sent successfully; otherwise, false.

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendTextAsync() [2/2]

bool XmobiTea.ProtonNetServer.WsSession.SendTextAsync ( byte[] buffer,
int position,
int length )

Sends a text message asynchronously to the WebSocket connection with a specified position and length.

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

Implements XmobiTea.ProtonNetServer.IWsSession.

◆ SendUpgrade()

void XmobiTea.ProtonNetServer.WsSession.SendUpgrade ( HttpResponse response)

Sends a WebSocket upgrade response to the client.

Parameters
responseThe HTTP response containing the WebSocket upgrade information.

Implements XmobiTea.ProtonNetCommon.IWebSocket.


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