My Project
Loading...
Searching...
No Matches
Public Member Functions | Properties | List of all members
WebSocketSharp.Server.WebSocketSessionManager Class Reference

Provides the management function for the sessions in a WebSocket service. More...

Public Member Functions

void Broadcast (byte[] data)
 Sends the specified data to every client in the WebSocket service.
 
void Broadcast (string data)
 Sends the specified data to every client in the WebSocket service.
 
void Broadcast (Stream stream, int length)
 Sends the data from the specified stream instance to every client in the WebSocket service.
 
void BroadcastAsync (byte[] data, Action completed)
 Sends the specified data asynchronously to every client in the WebSocket service.
 
void BroadcastAsync (string data, Action completed)
 Sends the specified data asynchronously to every client in the WebSocket service.
 
void BroadcastAsync (Stream stream, int length, Action completed)
 Sends the data from the specified stream instance asynchronously to every client in the WebSocket service.
 
void CloseSession (string id)
 Closes the session with the specified ID.
 
void CloseSession (string id, ushort code, string reason)
 Closes the session with the specified ID, code, and reason.
 
void CloseSession (string id, CloseStatusCode code, string reason)
 Closes the session with the specified ID, code, and reason.
 
bool PingTo (string id)
 Sends a ping to the client using the specified session.
 
bool PingTo (string message, string id)
 Sends a ping with the specified message to the client using the specified session.
 
void SendTo (byte[] data, string id)
 Sends the specified data to the client using the specified session.
 
void SendTo (string data, string id)
 Sends the specified data to the client using the specified session.
 
void SendTo (Stream stream, int length, string id)
 Sends the data from the specified stream instance to the client using the specified session.
 
void SendToAsync (byte[] data, string id, Action< bool > completed)
 Sends the specified data asynchronously to the client using the specified session.
 
void SendToAsync (string data, string id, Action< bool > completed)
 Sends the specified data asynchronously to the client using the specified session.
 
void SendToAsync (Stream stream, int length, string id, Action< bool > completed)
 Sends the data from the specified stream instance asynchronously to the client using the specified session.
 
void Sweep ()
 Cleans up the inactive sessions in the WebSocket service.
 
bool TryGetSession (string id, out IWebSocketSession session)
 Tries to get the session instance with the specified ID.
 

Properties

IEnumerable< string > ActiveIDs [get]
 Gets the IDs for the active sessions in the WebSocket service.
 
int Count [get]
 Gets the number of the sessions in the WebSocket service.
 
IEnumerable< string > IDs [get]
 Gets the IDs for the sessions in the WebSocket service.
 
IEnumerable< string > InactiveIDs [get]
 Gets the IDs for the inactive sessions in the WebSocket service.
 
IWebSocketSession this[string id] [get]
 Gets the session instance with the specified ID.
 
bool KeepClean [get, set]
 Gets or sets a value indicating whether the inactive sessions in the WebSocket service are cleaned up periodically.
 
IEnumerable< IWebSocketSessionSessions [get]
 Gets the session instances in the WebSocket service.
 
TimeSpan WaitTime [get, set]
 Gets or sets the time to wait for the response to the WebSocket Ping or Close.
 

Detailed Description

Provides the management function for the sessions in a WebSocket service.

This class manages the sessions in a WebSocket service provided by the WebSocketServer or HttpServer class.

Member Function Documentation

◆ Broadcast() [1/3]

void WebSocketSharp.Server.WebSocketSessionManager.Broadcast ( byte[]  data)
inline

Sends the specified data to every client in the WebSocket service.

Parameters
dataAn array of byte that specifies the binary data to send.
Exceptions
InvalidOperationExceptionThe current state of the service is not Start.
ArgumentNullExceptiondata is null.

◆ Broadcast() [2/3]

void WebSocketSharp.Server.WebSocketSessionManager.Broadcast ( Stream  stream,
int  length 
)
inline

Sends the data from the specified stream instance to every client in the WebSocket service.

Parameters
streamA Stream instance from which to read the data to send. The data is sent as the binary data.
lengthAn int that specifies the number of bytes to send.
Exceptions
InvalidOperationExceptionThe current state of the service is not Start.
ArgumentNullExceptionstream is null.
ArgumentExceptionstream cannot be read. -or- length is less than 1. -or- No data could be read from stream .

◆ Broadcast() [3/3]

void WebSocketSharp.Server.WebSocketSessionManager.Broadcast ( string  data)
inline

Sends the specified data to every client in the WebSocket service.

Parameters
dataA string that specifies the text data to send.
Exceptions
InvalidOperationExceptionThe current state of the service is not Start.
ArgumentNullExceptiondata is null.
ArgumentExceptiondata could not be UTF-8-encoded.

◆ BroadcastAsync() [1/3]

void WebSocketSharp.Server.WebSocketSessionManager.BroadcastAsync ( byte[]  data,
Action  completed 
)
inline

Sends the specified data asynchronously to every client in the WebSocket service.

This method does not wait for the send to be complete.

Parameters
dataAn array of byte that specifies the binary data to send.
completedAn Action delegate or null if not needed. The delegate invokes the method called when the send is complete.
Exceptions
InvalidOperationExceptionThe current state of the service is not Start.
ArgumentNullExceptiondata is null.

◆ BroadcastAsync() [2/3]

void WebSocketSharp.Server.WebSocketSessionManager.BroadcastAsync ( Stream  stream,
int  length,
Action  completed 
)
inline

Sends the data from the specified stream instance asynchronously to every client in the WebSocket service.

This method does not wait for the send to be complete.

Parameters
streamA Stream instance from which to read the data to send. The data is sent as the binary data.
lengthAn int that specifies the number of bytes to send.
completedAn Action delegate or null if not needed. The delegate invokes the method called when the send is complete.
Exceptions
InvalidOperationExceptionThe current state of the service is not Start.
ArgumentNullExceptionstream is null.
ArgumentExceptionstream cannot be read. -or- length is less than 1. -or- No data could be read from stream .

◆ BroadcastAsync() [3/3]

void WebSocketSharp.Server.WebSocketSessionManager.BroadcastAsync ( string  data,
Action  completed 
)
inline

Sends the specified data asynchronously to every client in the WebSocket service.

This method does not wait for the send to be complete.

Parameters
dataA string that specifies the text data to send.
completedAn Action delegate or null if not needed. The delegate invokes the method called when the send is complete.
Exceptions
InvalidOperationExceptionThe current state of the service is not Start.
ArgumentNullExceptiondata is null.
ArgumentExceptiondata could not be UTF-8-encoded.

◆ CloseSession() [1/3]

void WebSocketSharp.Server.WebSocketSessionManager.CloseSession ( string  id)
inline

Closes the session with the specified ID.

Parameters
idA string that specifies the ID of the session to close.
Exceptions
ArgumentNullExceptionid is null.
ArgumentExceptionid is an empty string.
InvalidOperationExceptionThe session could not be found.

◆ CloseSession() [2/3]

void WebSocketSharp.Server.WebSocketSessionManager.CloseSession ( string  id,
CloseStatusCode  code,
string  reason 
)
inline

Closes the session with the specified ID, code, and reason.

Parameters
idA string that specifies the ID of the session to close.
codeOne of the CloseStatusCode enum values. It specifies the status code indicating the reason for the close.
reasonA string that specifies the reason for the close. The size must be 123 bytes or less in UTF-8.
Exceptions
ArgumentNullExceptionid is null.
ArgumentExceptionid is an empty string. -or- code is CloseStatusCode.MandatoryExtension. -or- code is CloseStatusCode.NoStatus and there is reason. -or- reason could not be UTF-8-encoded.
InvalidOperationExceptionThe session could not be found.
ArgumentOutOfRangeExceptionThe size of reason is greater than 123 bytes.

◆ CloseSession() [3/3]

void WebSocketSharp.Server.WebSocketSessionManager.CloseSession ( string  id,
ushort  code,
string  reason 
)
inline

Closes the session with the specified ID, code, and reason.

Parameters
idA string that specifies the ID of the session to close.
codeA ushort that specifies the status code indicating the reason for the close. The status codes are defined in Section 7.4of RFC 6455.
reasonA string that specifies the reason for the close. The size must be 123 bytes or less in UTF-8.
Exceptions
ArgumentNullExceptionid is null.
ArgumentExceptionid is an empty string. -or- code is 1010 (mandatory extension). -or- code is 1005 (no status) and there is reason. -or- reason could not be UTF-8-encoded.
InvalidOperationExceptionThe session could not be found.
ArgumentOutOfRangeExceptioncode is less than 1000 or greater than 4999. -or- The size of reason is greater than 123 bytes.

◆ PingTo() [1/2]

bool WebSocketSharp.Server.WebSocketSessionManager.PingTo ( string  id)
inline

Sends a ping to the client using the specified session.

Returns
true if the send has done with no error and a pong has been received from the client within a time; otherwise, false.
Parameters
idA string that specifies the ID of the session.
Exceptions
ArgumentNullExceptionid is null.
ArgumentExceptionid is an empty string.
InvalidOperationExceptionThe session could not be found.

◆ PingTo() [2/2]

bool WebSocketSharp.Server.WebSocketSessionManager.PingTo ( string  message,
string  id 
)
inline

Sends a ping with the specified message to the client using the specified session.

Returns
true if the send has done with no error and a pong has been received from the client within a time; otherwise, false.
Parameters
messageA string that specifies the message to send. The size must be 125 bytes or less in UTF-8.
idA string that specifies the ID of the session.
Exceptions
ArgumentNullExceptionid is null.
ArgumentExceptionid is an empty string. -or- message could not be UTF-8-encoded.
InvalidOperationExceptionThe session could not be found.
ArgumentOutOfRangeExceptionThe size of message is greater than 125 bytes.

◆ SendTo() [1/3]

void WebSocketSharp.Server.WebSocketSessionManager.SendTo ( byte[]  data,
string  id 
)
inline

Sends the specified data to the client using the specified session.

Parameters
dataAn array of byte that specifies the binary data to send.
idA string that specifies the ID of the session.
Exceptions
ArgumentNullExceptionid is null. -or- data is null.
ArgumentExceptionid is an empty string.
InvalidOperationExceptionThe session could not be found. -or- The current state of the WebSocket connection is not Open.

◆ SendTo() [2/3]

void WebSocketSharp.Server.WebSocketSessionManager.SendTo ( Stream  stream,
int  length,
string  id 
)
inline

Sends the data from the specified stream instance to the client using the specified session.

Parameters
streamA Stream instance from which to read the data to send. The data is sent as the binary data.
lengthAn int that specifies the number of bytes to send.
idA string that specifies the ID of the session.
Exceptions
ArgumentNullExceptionid is null. -or- stream is null.
ArgumentExceptionid is an empty string. -or- stream cannot be read. -or- length is less than 1. -or- No data could be read from stream .
InvalidOperationExceptionThe session could not be found. -or- The current state of the WebSocket connection is not Open.

◆ SendTo() [3/3]

void WebSocketSharp.Server.WebSocketSessionManager.SendTo ( string  data,
string  id 
)
inline

Sends the specified data to the client using the specified session.

Parameters
dataA string that specifies the text data to send.
idA string that specifies the ID of the session.
Exceptions
ArgumentNullExceptionid is null. -or- data is null.
ArgumentExceptionid is an empty string. -or- data could not be UTF-8-encoded.
InvalidOperationExceptionThe session could not be found. -or- The current state of the WebSocket connection is not Open.

◆ SendToAsync() [1/3]

void WebSocketSharp.Server.WebSocketSessionManager.SendToAsync ( byte[]  data,
string  id,
Action< bool >  completed 
)
inline

Sends the specified data asynchronously to the client using the specified session.

This method does not wait for the send to be complete.

Parameters
dataAn array of byte that specifies the binary data to send.
idA string that specifies the ID of the session.
completedAn Action<bool> delegate or null if not needed. The delegate invokes the method called when the send is complete. true is passed to the method if the send has done with no error; otherwise, false.
Exceptions
ArgumentNullExceptionid is null. -or- data is null.
ArgumentExceptionid is an empty string.
InvalidOperationExceptionThe session could not be found. -or- The current state of the WebSocket connection is not Open.

◆ SendToAsync() [2/3]

void WebSocketSharp.Server.WebSocketSessionManager.SendToAsync ( Stream  stream,
int  length,
string  id,
Action< bool >  completed 
)
inline

Sends the data from the specified stream instance asynchronously to the client using the specified session.

This method does not wait for the send to be complete.

Parameters
streamA Stream instance from which to read the data to send. The data is sent as the binary data.
lengthAn int that specifies the number of bytes to send.
idA string that specifies the ID of the session.
completedAn Action<bool> delegate or null if not needed. The delegate invokes the method called when the send is complete. true is passed to the method if the send has done with no error; otherwise, false.
Exceptions
ArgumentNullExceptionid is null. -or- stream is null.
ArgumentExceptionid is an empty string. -or- stream cannot be read. -or- length is less than 1. -or- No data could be read from stream .
InvalidOperationExceptionThe session could not be found. -or- The current state of the WebSocket connection is not Open.

◆ SendToAsync() [3/3]

void WebSocketSharp.Server.WebSocketSessionManager.SendToAsync ( string  data,
string  id,
Action< bool >  completed 
)
inline

Sends the specified data asynchronously to the client using the specified session.

This method does not wait for the send to be complete.

Parameters
dataA string that specifies the text data to send.
idA string that specifies the ID of the session.
completedAn Action<bool> delegate or null if not needed. The delegate invokes the method called when the send is complete. true is passed to the method if the send has done with no error; otherwise, false.
Exceptions
ArgumentNullExceptionid is null. -or- data is null.
ArgumentExceptionid is an empty string. -or- data could not be UTF-8-encoded.
InvalidOperationExceptionThe session could not be found. -or- The current state of the WebSocket connection is not Open.

◆ TryGetSession()

bool WebSocketSharp.Server.WebSocketSessionManager.TryGetSession ( string  id,
out IWebSocketSession  session 
)
inline

Tries to get the session instance with the specified ID.

Returns
true if the session is successfully found; otherwise, false.
Parameters
idA string that specifies the ID of the session to find.
sessionWhen this method returns, a IWebSocketSession instance or null if not found. The session instance provides the function to access the information in the session.
Exceptions
ArgumentNullExceptionid is null.
ArgumentExceptionid is an empty string.

Property Documentation

◆ ActiveIDs

IEnumerable<string> WebSocketSharp.Server.WebSocketSessionManager.ActiveIDs
get

Gets the IDs for the active sessions in the WebSocket service.

An IEnumerable<string> instance.

It provides an enumerator which supports the iteration over the collection of the IDs for the active sessions.

◆ Count

int WebSocketSharp.Server.WebSocketSessionManager.Count
get

Gets the number of the sessions in the WebSocket service.

An int that represents the number of the sessions.

◆ IDs

IEnumerable<string> WebSocketSharp.Server.WebSocketSessionManager.IDs
get

Gets the IDs for the sessions in the WebSocket service.

An IEnumerable<string> instance.

It provides an enumerator which supports the iteration over the collection of the IDs for the sessions.

◆ InactiveIDs

IEnumerable<string> WebSocketSharp.Server.WebSocketSessionManager.InactiveIDs
get

Gets the IDs for the inactive sessions in the WebSocket service.

An IEnumerable<string> instance.

It provides an enumerator which supports the iteration over the collection of the IDs for the inactive sessions.

◆ KeepClean

bool WebSocketSharp.Server.WebSocketSessionManager.KeepClean
getset

Gets or sets a value indicating whether the inactive sessions in the WebSocket service are cleaned up periodically.

The set operation does nothing if the service has already started or it is shutting down.

true if the inactive sessions are cleaned up every 60 seconds; otherwise, false.

◆ Sessions

IEnumerable<IWebSocketSession> WebSocketSharp.Server.WebSocketSessionManager.Sessions
get

Gets the session instances in the WebSocket service.

An IEnumerable<IWebSocketSession> instance.

It provides an enumerator which supports the iteration over the collection of the session instances.

◆ this[string id]

IWebSocketSession WebSocketSharp.Server.WebSocketSessionManager.this[string id]
get

Gets the session instance with the specified ID.

A IWebSocketSession instance or null if not found.

The session instance provides the function to access the information in the session.

Parameters
idA string that specifies the ID of the session to find.
Exceptions
ArgumentNullExceptionid is null.
ArgumentExceptionid is an empty string.

◆ WaitTime

TimeSpan WebSocketSharp.Server.WebSocketSessionManager.WaitTime
getset

Gets or sets the time to wait for the response to the WebSocket Ping or Close.

The set operation does nothing if the service has already started or it is shutting down.

A TimeSpan to wait for the response.

Exceptions
ArgumentOutOfRangeExceptionThe value specified for a set operation is zero or less.

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