Class WebSocketSessionManager
Inheritance
Inherited Members
Namespace: Mars.Common.Socket.Server
Assembly: Mars.Common.dll
Syntax
public class WebSocketSessionManager
  Remarks
Properties
| Improve this Doc View SourceActiveIDs
Declaration
public IEnumerable<string> ActiveIDs { get; }
  Property Value
| Type | Description | 
|---|---|
| System.Collections.Generic.IEnumerable<System.String> | 
 
    An  It provides an enumerator which supports the iteration over the collection of the IDs for the active sessions.  | 
      
Remarks
Count
Declaration
public int Count { get; }
  Property Value
| Type | Description | 
|---|---|
| System.Int32 | An System.Int32 that represents the number of the sessions. | 
Remarks
IDs
Declaration
public IEnumerable<string> IDs { get; }
  Property Value
| Type | Description | 
|---|---|
| System.Collections.Generic.IEnumerable<System.String> | 
 
    An  It provides an enumerator which supports the iteration over the collection of the IDs for the sessions.  | 
      
Remarks
InactiveIDs
Declaration
public IEnumerable<string> InactiveIDs { get; }
  Property Value
| Type | Description | 
|---|---|
| System.Collections.Generic.IEnumerable<System.String> | 
 
    An  It provides an enumerator which supports the iteration over the collection of the IDs for the inactive sessions.  | 
      
Remarks
Item[String]
id.
Declaration
public IWebSocketSession this[string id] { get; }
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | id | A System.String that represents the ID of the session to find. | 
Property Value
| Type | Description | 
|---|---|
| IWebSocketSession | 
 A IWebSocketSession instance or null if not found. The session instance provides the function to access the information in the session.  | 
      
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.ArgumentNullException | 
id is null.
 | 
      
| System.ArgumentException | 
id is an empty string.
 | 
      
KeepClean
Declaration
public bool KeepClean { get; set; }
  Property Value
| Type | Description | 
|---|---|
| System.Boolean | 
true if the inactive sessions are cleaned up every 60 seconds;
otherwise, false.
 | 
      
Remarks
Sessions
Declaration
public IEnumerable<IWebSocketSession> Sessions { get; }
  Property Value
| Type | Description | 
|---|---|
| System.Collections.Generic.IEnumerable<IWebSocketSession> | 
 
    An  It provides an enumerator which supports the iteration over the collection of the session instances.  | 
      
Remarks
WaitTime
Declaration
public TimeSpan WaitTime { get; set; }
  Property Value
| Type | Description | 
|---|---|
| System.TimeSpan | A System.TimeSpan to wait for the response. | 
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.ArgumentOutOfRangeException | The value specified for a set operation is zero or less. | 
Methods
| Improve this Doc View SourceBroadcast(Byte[])
data to every client in the WebSocket service.
Declaration
public void Broadcast(byte[] data)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.Byte[] | data | An array of System.Byte that represents the binary data to send. | 
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.InvalidOperationException | The current state of the manager is not Start. | 
| System.ArgumentNullException | 
data is null.
 | 
      
Broadcast(Stream, Int32)
stream to every client in
the WebSocket service.
Declaration
public void Broadcast(Stream stream, int length)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.IO.Stream | stream | A System.IO.Stream instance from which to read the data to send. | 
| System.Int32 | length | An System.Int32 that specifies the number of bytes to send. | 
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.InvalidOperationException | The current state of the manager is not Start. | 
| System.ArgumentNullException | 
stream is null.
 | 
      
| System.ArgumentException | 
 
 -or- 
 -or- 
    No data could be read from   | 
      
Broadcast(String)
data to every client in the WebSocket service.
Declaration
public void Broadcast(string data)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | data | A System.String that represents the text data to send. | 
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.InvalidOperationException | The current state of the manager is not Start. | 
| System.ArgumentNullException | 
data is null.
 | 
      
| System.ArgumentException | 
data could not be UTF-8-encoded.
 | 
      
BroadcastAsync(Byte[], Action)
data asynchronously to every client in
the WebSocket service.
Declaration
public void BroadcastAsync(byte[] data, Action completed)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.Byte[] | data | An array of System.Byte that represents the binary data to send. | 
| System.Action | completed | 
 An System.Action delegate or null if not needed. The delegate invokes the method called when the send is complete.  | 
      
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.InvalidOperationException | The current state of the manager is not Start. | 
| System.ArgumentNullException | 
data is null.
 | 
      
BroadcastAsync(Stream, Int32, Action)
stream asynchronously to
every client in the WebSocket service.
Declaration
public void BroadcastAsync(Stream stream, int length, Action completed)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.IO.Stream | stream | A System.IO.Stream instance from which to read the data to send. | 
| System.Int32 | length | An System.Int32 that specifies the number of bytes to send. | 
| System.Action | completed | 
 An System.Action delegate or null if not needed. The delegate invokes the method called when the send is complete.  | 
      
Remarks
The data is sent as the binary data.
This method does not wait for the send to be complete.
Exceptions
| Type | Condition | 
|---|---|
| System.InvalidOperationException | The current state of the manager is not Start. | 
| System.ArgumentNullException | 
stream is null.
 | 
      
| System.ArgumentException | 
 
 -or- 
 -or- 
    No data could be read from   | 
      
BroadcastAsync(String, Action)
data asynchronously to every client in
the WebSocket service.
Declaration
public void BroadcastAsync(string data, Action completed)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | data | A System.String that represents the text data to send. | 
| System.Action | completed | 
 An System.Action delegate or null if not needed. The delegate invokes the method called when the send is complete.  | 
      
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.InvalidOperationException | The current state of the manager is not Start. | 
| System.ArgumentNullException | 
data is null.
 | 
      
| System.ArgumentException | 
data could not be UTF-8-encoded.
 | 
      
Broadping()
Declaration
[Obsolete("This method will be removed.")]
public Dictionary<string, bool> Broadping()
  Returns
| Type | Description | 
|---|---|
| System.Collections.Generic.Dictionary<System.String, System.Boolean> | 
 
    A  It represents a collection of pairs of a session ID and a value indicating whether a pong has been received from the client within a time.  | 
      
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.InvalidOperationException | The current state of the manager is not Start. | 
Broadping(String)
message to every client in
the WebSocket service.
Declaration
[Obsolete("This method will be removed.")]
public Dictionary<string, bool> Broadping(string message)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | message | 
 A System.String that represents the message to send. The size must be 125 bytes or less in UTF-8.  | 
      
Returns
| Type | Description | 
|---|---|
| System.Collections.Generic.Dictionary<System.String, System.Boolean> | 
 
    A  It represents a collection of pairs of a session ID and a value indicating whether a pong has been received from the client within a time.  | 
      
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.InvalidOperationException | The current state of the manager is not Start. | 
| System.ArgumentException | 
message could not be UTF-8-encoded.
 | 
      
| System.ArgumentOutOfRangeException | 
The size of message is greater than 125 bytes.
 | 
      
CloseSession(String, CloseStatusCode, String)
code and
reason.
Declaration
public void CloseSession(string id, CloseStatusCode code, string reason)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | id | A System.String that represents the ID of the session to close. | 
| CloseStatusCode | code | 
 One of the CloseStatusCode enum values. It represents the status code indicating the reason for the close.  | 
      
| System.String | reason | 
 A System.String that represents the reason for the close. The size must be 123 bytes or less in UTF-8.  | 
      
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.ArgumentNullException | 
id is null.
 | 
      
| System.ArgumentException | 
 
 -or- 
 -or- 
 -or- 
  | 
      
| System.InvalidOperationException | The session could not be found. | 
| System.ArgumentOutOfRangeException | 
The size of reason is greater than 123 bytes.
 | 
      
CloseSession(String, UInt16, String)
code and
reason.
Declaration
public void CloseSession(string id, ushort code, string reason)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | id | A System.String that represents the ID of the session to close. | 
| System.UInt16 | code | 
 A System.UInt16 that represents the status code indicating the reason for the close. The status codes are defined in Section 7.4 of RFC 6455.  | 
      
| System.String | reason | 
 A System.String that represents the reason for the close. The size must be 123 bytes or less in UTF-8.  | 
      
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.ArgumentNullException | 
id is null.
 | 
      
| System.ArgumentException | 
 
 -or- 
 -or- 
 -or- 
  | 
      
| System.InvalidOperationException | The session could not be found. | 
| System.ArgumentOutOfRangeException | 
 
 -or- 
    The size of   | 
      
CloseSession(String)
Declaration
public void CloseSession(string id)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | id | A System.String that represents the ID of the session to close. | 
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.ArgumentNullException | 
id is null.
 | 
      
| System.ArgumentException | 
id is an empty string.
 | 
      
| System.InvalidOperationException | The session could not be found. | 
PingTo(String, String)
message to the client using
the specified session.
Declaration
public bool PingTo(string message, string id)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | message | 
 A System.String that represents the message to send. The size must be 125 bytes or less in UTF-8.  | 
      
| System.String | id | A System.String that represents the ID of the session. | 
Returns
| Type | Description | 
|---|---|
| System.Boolean | 
true if the send has done with no error and a pong has been
received from the client within a time; otherwise, false.
 | 
      
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.ArgumentNullException | 
id is null.
 | 
      
| System.ArgumentException | 
 
 -or- 
  | 
      
| System.InvalidOperationException | The session could not be found. | 
| System.ArgumentOutOfRangeException | 
The size of message is greater than 125 bytes.
 | 
      
PingTo(String)
Declaration
public bool PingTo(string id)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | id | A System.String that represents the ID of the session. | 
Returns
| Type | Description | 
|---|---|
| System.Boolean | 
true if the send has done with no error and a pong has been
received from the client within a time; otherwise, false.
 | 
      
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.ArgumentNullException | 
id is null.
 | 
      
| System.ArgumentException | 
id is an empty string.
 | 
      
| System.InvalidOperationException | The session could not be found. | 
SendTo(Byte[], String)
data to the client using the specified session.
Declaration
public void SendTo(byte[] data, string id)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.Byte[] | data | An array of System.Byte that represents the binary data to send. | 
| System.String | id | A System.String that represents the ID of the session. | 
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.ArgumentNullException | 
 
 -or- 
  | 
      
| System.ArgumentException | 
id is an empty string.
 | 
      
| System.InvalidOperationException | 
 The session could not be found. -or- The current state of the WebSocket connection is not Open.  | 
      
SendTo(Stream, Int32, String)
stream to the client using
the specified session.
Declaration
public void SendTo(Stream stream, int length, string id)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.IO.Stream | stream | A System.IO.Stream instance from which to read the data to send. | 
| System.Int32 | length | An System.Int32 that specifies the number of bytes to send. | 
| System.String | id | A System.String that represents the ID of the session. | 
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.ArgumentNullException | 
 
 -or- 
  | 
      
| System.ArgumentException | 
 
 -or- 
 -or- 
 -or- 
    No data could be read from   | 
      
| System.InvalidOperationException | 
 The session could not be found. -or- The current state of the WebSocket connection is not Open.  | 
      
SendTo(String, String)
data to the client using the specified session.
Declaration
public void SendTo(string data, string id)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | data | A System.String that represents the text data to send. | 
| System.String | id | A System.String that represents the ID of the session. | 
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.ArgumentNullException | 
 
 -or- 
  | 
      
| System.ArgumentException | 
 
 -or- 
  | 
      
| System.InvalidOperationException | 
 The session could not be found. -or- The current state of the WebSocket connection is not Open.  | 
      
SendToAsync(Byte[], String, Action<Boolean>)
data asynchronously to the client using
the specified session.
Declaration
public void SendToAsync(byte[] data, string id, Action<bool> completed)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.Byte[] | data | An array of System.Byte that represents the binary data to send. | 
| System.String | id | A System.String that represents the ID of the session. | 
| System.Action<System.Boolean> | completed | 
 
    An  The delegate invokes the method called when the send is complete. 
  | 
      
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.ArgumentNullException | 
 
 -or- 
  | 
      
| System.ArgumentException | 
id is an empty string.
 | 
      
| System.InvalidOperationException | 
 The session could not be found. -or- The current state of the WebSocket connection is not Open.  | 
      
SendToAsync(Stream, Int32, String, Action<Boolean>)
stream asynchronously to
the client using the specified session.
Declaration
public void SendToAsync(Stream stream, int length, string id, Action<bool> completed)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.IO.Stream | stream | A System.IO.Stream instance from which to read the data to send. | 
| System.Int32 | length | An System.Int32 that specifies the number of bytes to send. | 
| System.String | id | A System.String that represents the ID of the session. | 
| System.Action<System.Boolean> | completed | 
 
    An  The delegate invokes the method called when the send is complete. 
  | 
      
Remarks
The data is sent as the binary data.
This method does not wait for the send to be complete.
Exceptions
| Type | Condition | 
|---|---|
| System.ArgumentNullException | 
 
 -or- 
  | 
      
| System.ArgumentException | 
 
 -or- 
 -or- 
 -or- 
    No data could be read from   | 
      
| System.InvalidOperationException | 
 The session could not be found. -or- The current state of the WebSocket connection is not Open.  | 
      
SendToAsync(String, String, Action<Boolean>)
data asynchronously to the client using
the specified session.
Declaration
public void SendToAsync(string data, string id, Action<bool> completed)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | data | A System.String that represents the text data to send. | 
| System.String | id | A System.String that represents the ID of the session. | 
| System.Action<System.Boolean> | completed | 
 
    An  The delegate invokes the method called when the send is complete. 
  | 
      
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.ArgumentNullException | 
 
 -or- 
  | 
      
| System.ArgumentException | 
 
 -or- 
  | 
      
| System.InvalidOperationException | 
 The session could not be found. -or- The current state of the WebSocket connection is not Open.  | 
      
Sweep()
Declaration
public void Sweep()
  Remarks
TryGetSession(String, out IWebSocketSession)
id.
Declaration
public bool TryGetSession(string id, out IWebSocketSession session)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | id | A System.String that represents the ID of the session to find. | 
| IWebSocketSession | session | 
 When this method returns, a IWebSocketSession instance or null if not found. The session instance provides the function to access the information in the session.  | 
      
Returns
| Type | Description | 
|---|---|
| System.Boolean | 
true if the session is successfully found; otherwise,
false.
 | 
      
Remarks
Exceptions
| Type | Condition | 
|---|---|
| System.ArgumentNullException | 
id is null.
 | 
      
| System.ArgumentException | 
id is an empty string.
 |