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

Exposes a set of methods and properties used to define the behavior of a WebSocket service provided by the WebSocketServer or HttpServer class. More...

Inheritance diagram for WebSocketSharp.Server.WebSocketBehavior:
WebSocketSharp.Server.IWebSocketSession RconListener WebSocketListener.ListenerWebSocketBehavior

Protected Member Functions

 WebSocketBehavior ()
 Initializes a new instance of the WebSocketBehavior class.
 
void Close ()
 Closes the WebSocket connection for a session.
 
void Close (ushort code, string reason)
 Closes the WebSocket connection for a session with the specified code and reason.
 
void Close (CloseStatusCode code, string reason)
 Closes the WebSocket connection for a session with the specified code and reason.
 
void CloseAsync ()
 Closes the WebSocket connection for a session asynchronously.
 
void CloseAsync (ushort code, string reason)
 Closes the WebSocket connection for a session asynchronously with the specified code and reason.
 
void CloseAsync (CloseStatusCode code, string reason)
 Closes the WebSocket connection for a session asynchronously with the specified code and reason.
 
virtual void OnClose (CloseEventArgs e)
 Called when the WebSocket connection for a session has been closed.
 
virtual void OnError (ErrorEventArgs e)
 Called when the WebSocket interface for a session gets an error.
 
virtual void OnMessage (MessageEventArgs e)
 Called when the WebSocket interface for a session receives a message.
 
virtual void OnOpen ()
 Called when the WebSocket connection for a session has been established.
 
bool Ping ()
 Sends a ping to the client for a session.
 
bool Ping (string message)
 Sends a ping with the specified message to the client for a session.
 
void Send (byte[] data)
 Sends the specified data to the client for a session.
 
void Send (FileInfo fileInfo)
 Sends the specified file to the client for a session.
 
void Send (string data)
 Sends the specified data to the client for a session.
 
void Send (Stream stream, int length)
 Sends the data from the specified stream instance to the client for a session.
 
void SendAsync (byte[] data, Action< bool > completed)
 Sends the specified data to the client for a session asynchronously.
 
void SendAsync (FileInfo fileInfo, Action< bool > completed)
 Sends the specified file to the client for a session asynchronously.
 
void SendAsync (string data, Action< bool > completed)
 Sends the specified data to the client for a session asynchronously.
 
void SendAsync (Stream stream, int length, Action< bool > completed)
 Sends the data from the specified stream instance to the client for a session asynchronously.
 

Properties

NameValueCollection Headers [get]
 Gets the HTTP headers for a session.
 
bool IsAlive [get]
 Gets a value indicating whether the communication is possible for a session.
 
NameValueCollection QueryString [get]
 Gets the query string for a session.
 
WebSocketState ReadyState [get]
 Gets the current state of the WebSocket interface for a session.
 
WebSocketSessionManager Sessions [get]
 Gets the management function for the sessions in the service.
 
IPrincipal User [get]
 Gets the client information for a session.
 
System.Net.IPEndPoint UserEndPoint [get]
 Gets the client endpoint for a session.
 
Func< CookieCollection, CookieCollection, bool > CookiesValidator [get, set]
 Gets or sets the delegate used to validate the HTTP cookies.
 
bool EmitOnPing [get, set]
 Gets or sets a value indicating whether the message event is emitted when the WebSocket interface for a session receives a ping.
 
string ID [get]
 Gets the unique ID of a session.
 
bool IgnoreExtensions [get, set]
 Gets or sets a value indicating whether the WebSocket interface for a session ignores the Sec-WebSocket-Extensions header.
 
Func< string, bool > OriginValidator [get, set]
 Gets or sets the delegate used to validate the Origin header.
 
string Protocol [get, set]
 Gets or sets the name of the WebSocket subprotocol for a session.
 
DateTime StartTime [get]
 Gets the time that a session has started.
 
- Properties inherited from WebSocketSharp.Server.IWebSocketSession
string ID [get]
 Gets the unique ID of the session.
 
DateTime StartTime [get]
 Gets the time that the session has started.
 
WebSocket WebSocket [get]
 Gets the WebSocket interface for the session.
 

Detailed Description

Exposes a set of methods and properties used to define the behavior of a WebSocket service provided by the WebSocketServer or HttpServer class.

This class is an abstract class.

Member Function Documentation

◆ Close() [1/3]

void WebSocketSharp.Server.WebSocketBehavior.Close ( )
inlineprotected

Closes the WebSocket connection for a session.

This method does nothing if the current state of the WebSocket interface is Closing or Closed.

Exceptions
InvalidOperationExceptionThe session has not started yet.

◆ Close() [2/3]

void WebSocketSharp.Server.WebSocketBehavior.Close ( CloseStatusCode  code,
string  reason 
)
inlineprotected

Closes the WebSocket connection for a session with the specified code and reason.

This method does nothing if the current state of the WebSocket interface is Closing or Closed.

Parameters
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. Its size must be 123 bytes or less in UTF-8.
Exceptions
InvalidOperationExceptionThe session has not started yet.
ArgumentExceptioncode is CloseStatusCode.MandatoryExtension. -or- code is CloseStatusCode.NoStatus and reason is specified. -or- reason could not be UTF-8-encoded.
ArgumentOutOfRangeExceptionThe size of reason is greater than 123 bytes.

◆ Close() [3/3]

void WebSocketSharp.Server.WebSocketBehavior.Close ( ushort  code,
string  reason 
)
inlineprotected

Closes the WebSocket connection for a session with the specified code and reason.

This method does nothing if the current state of the WebSocket interface is Closing or Closed.

Parameters
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. Its size must be 123 bytes or less in UTF-8.
Exceptions
InvalidOperationExceptionThe session has not started yet.
ArgumentOutOfRangeExceptioncode is less than 1000 or greater than 4999. -or- The size of reason is greater than 123 bytes.
ArgumentExceptioncode is 1010 (mandatory extension). -or- code is 1005 (no status) and reason is specified. -or- reason could not be UTF-8-encoded.

◆ CloseAsync() [1/3]

void WebSocketSharp.Server.WebSocketBehavior.CloseAsync ( )
inlineprotected

Closes the WebSocket connection for a session asynchronously.

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

This method does nothing if the current state of the WebSocket interface is Closing or Closed.

Exceptions
InvalidOperationExceptionThe session has not started yet.

◆ CloseAsync() [2/3]

void WebSocketSharp.Server.WebSocketBehavior.CloseAsync ( CloseStatusCode  code,
string  reason 
)
inlineprotected

Closes the WebSocket connection for a session asynchronously with the specified code and reason.

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

This method does nothing if the current state of the WebSocket interface is Closing or Closed.

Parameters
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. Its size must be 123 bytes or less in UTF-8.
Exceptions
InvalidOperationExceptionThe session has not started yet.
ArgumentExceptioncode is CloseStatusCode.MandatoryExtension. -or- code is CloseStatusCode.NoStatus and reason is specified. -or- reason could not be UTF-8-encoded.
ArgumentOutOfRangeExceptionThe size of reason is greater than 123 bytes.

◆ CloseAsync() [3/3]

void WebSocketSharp.Server.WebSocketBehavior.CloseAsync ( ushort  code,
string  reason 
)
inlineprotected

Closes the WebSocket connection for a session asynchronously with the specified code and reason.

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

This method does nothing if the current state of the WebSocket interface is Closing or Closed.

Parameters
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. Its size must be 123 bytes or less in UTF-8.
Exceptions
InvalidOperationExceptionThe session has not started yet.
ArgumentOutOfRangeExceptioncode is less than 1000 or greater than 4999. -or- The size of reason is greater than 123 bytes.
ArgumentExceptioncode is 1010 (mandatory extension). -or- code is 1005 (no status) and reason is specified. -or- reason could not be UTF-8-encoded.

◆ OnClose()

virtual void WebSocketSharp.Server.WebSocketBehavior.OnClose ( CloseEventArgs  e)
inlineprotectedvirtual

Called when the WebSocket connection for a session has been closed.

Parameters
eA CloseEventArgs that represents the event data passed from a WebSocket.OnClose event.

Reimplemented in RconListener, and WebSocketListener.ListenerWebSocketBehavior.

◆ OnError()

virtual void WebSocketSharp.Server.WebSocketBehavior.OnError ( ErrorEventArgs  e)
inlineprotectedvirtual

Called when the WebSocket interface for a session gets an error.

Parameters
eA ErrorEventArgs that represents the event data passed from a WebSocket.OnError event.

Reimplemented in RconListener, and WebSocketListener.ListenerWebSocketBehavior.

◆ OnMessage()

virtual void WebSocketSharp.Server.WebSocketBehavior.OnMessage ( MessageEventArgs  e)
inlineprotectedvirtual

Called when the WebSocket interface for a session receives a message.

Parameters
eA MessageEventArgs that represents the event data passed from a WebSocket.OnMessage event.

Reimplemented in RconListener, and WebSocketListener.ListenerWebSocketBehavior.

◆ OnOpen()

virtual void WebSocketSharp.Server.WebSocketBehavior.OnOpen ( )
inlineprotectedvirtual

Called when the WebSocket connection for a session has been established.

Reimplemented in RconListener, and WebSocketListener.ListenerWebSocketBehavior.

◆ Ping() [1/2]

bool WebSocketSharp.Server.WebSocketBehavior.Ping ( )
inlineprotected

Sends a ping to the client for a session.

Returns
true if the send has successfully done and a pong has been received within a time; otherwise, false.
Exceptions
InvalidOperationExceptionThe session has not started yet.

◆ Ping() [2/2]

bool WebSocketSharp.Server.WebSocketBehavior.Ping ( string  message)
inlineprotected

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

Returns
true if the send has successfully done and a pong has been received within a time; otherwise, false.
Parameters
messageA string that specifies the message to send. Its size must be 125 bytes or less in UTF-8.
Exceptions
InvalidOperationExceptionThe session has not started yet.
ArgumentExceptionmessage could not be UTF-8-encoded.
ArgumentOutOfRangeExceptionThe size of message is greater than 125 bytes.

◆ Send() [1/4]

void WebSocketSharp.Server.WebSocketBehavior.Send ( byte[]  data)
inlineprotected

Sends the specified data to the client for a session.

Parameters
dataAn array of byte that specifies the binary data to send.
Exceptions
InvalidOperationExceptionThe session has not started yet. -or- The current state of the WebSocket interface is not Open.
ArgumentNullExceptiondata is null.

◆ Send() [2/4]

void WebSocketSharp.Server.WebSocketBehavior.Send ( FileInfo  fileInfo)
inlineprotected

Sends the specified file to the client for a session.

Parameters
fileInfoA FileInfo that specifies the file to send. The file is sent as the binary data.
Exceptions
InvalidOperationExceptionThe session has not started yet. -or- The current state of the WebSocket interface is not Open.
ArgumentNullExceptionfileInfo is null.
ArgumentExceptionThe file does not exist. -or- The file could not be opened.

◆ Send() [3/4]

void WebSocketSharp.Server.WebSocketBehavior.Send ( Stream  stream,
int  length 
)
inlineprotected

Sends the data from the specified stream instance to the client for a 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.
Exceptions
InvalidOperationExceptionThe session has not started yet. -or- The current state of the WebSocket interface is not Open.
ArgumentNullExceptionstream is null.
ArgumentExceptionstream cannot be read. -or- length is less than 1. -or- No data could be read from stream .

◆ Send() [4/4]

void WebSocketSharp.Server.WebSocketBehavior.Send ( string  data)
inlineprotected

Sends the specified data to the client for a session.

Parameters
dataA string that specifies the text data to send.
Exceptions
InvalidOperationExceptionThe session has not started yet. -or- The current state of the WebSocket interface is not Open.
ArgumentNullExceptiondata is null.
ArgumentExceptiondata could not be UTF-8-encoded.

◆ SendAsync() [1/4]

void WebSocketSharp.Server.WebSocketBehavior.SendAsync ( byte[]  data,
Action< bool >  completed 
)
inlineprotected

Sends the specified data to the client for a session asynchronously.

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

Parameters
dataAn array of byte that specifies the binary data to send.
completedAn T:System.Action<bool> delegate. The delegate invokes the method called when the send is complete. The bool parameter passed to the method is true if the send has successfully done; otherwise, false. null if not necessary.
Exceptions
InvalidOperationExceptionThe session has not started yet. -or- The current state of the WebSocket interface is not Open.
ArgumentNullExceptiondata is null.

◆ SendAsync() [2/4]

void WebSocketSharp.Server.WebSocketBehavior.SendAsync ( FileInfo  fileInfo,
Action< bool >  completed 
)
inlineprotected

Sends the specified file to the client for a session asynchronously.

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

Parameters
fileInfoA FileInfo that specifies the file to send. The file is sent as the binary data.
completedAn T:System.Action<bool> delegate. The delegate invokes the method called when the send is complete. The bool parameter passed to the method is true if the send has successfully done; otherwise, false. null if not necessary.
Exceptions
InvalidOperationExceptionThe session has not started yet. -or- The current state of the WebSocket interface is not Open.
ArgumentNullExceptionfileInfo is null.
ArgumentExceptionThe file does not exist. -or- The file could not be opened.

◆ SendAsync() [3/4]

void WebSocketSharp.Server.WebSocketBehavior.SendAsync ( Stream  stream,
int  length,
Action< bool >  completed 
)
inlineprotected

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

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 T:System.Action<bool> delegate. The delegate invokes the method called when the send is complete. The bool parameter passed to the method is true if the send has successfully done; otherwise, false. null if not necessary.
Exceptions
InvalidOperationExceptionThe session has not started yet. -or- The current state of the WebSocket interface is not Open.
ArgumentNullExceptionstream is null.
ArgumentExceptionstream cannot be read. -or- length is less than 1. -or- No data could be read from stream .

◆ SendAsync() [4/4]

void WebSocketSharp.Server.WebSocketBehavior.SendAsync ( string  data,
Action< bool >  completed 
)
inlineprotected

Sends the specified data to the client for a session asynchronously.

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

Parameters
dataA string that specifies the text data to send.
completedAn T:System.Action<bool> delegate. The delegate invokes the method called when the send is complete. The bool parameter passed to the method is true if the send has successfully done; otherwise, false. null if not necessary.
Exceptions
InvalidOperationExceptionThe session has not started yet. -or- The current state of the WebSocket interface is not Open.
ArgumentNullExceptiondata is null.
ArgumentExceptiondata could not be UTF-8-encoded.

Property Documentation

◆ CookiesValidator

Func<CookieCollection, CookieCollection, bool> WebSocketSharp.Server.WebSocketBehavior.CookiesValidator
getset

Gets or sets the delegate used to validate the HTTP cookies.

A T:System.Func<CookieCollection, CookieCollection, bool> delegate.

The delegate invokes the method called when the WebSocket interface for a session validates the handshake request.

1st CookieCollection parameter passed to the method contains the cookies to validate.

2nd CookieCollection parameter passed to the method receives the cookies to send to the client.

The method must return true if the cookies are valid.

null if not necessary.

The default value is null.

◆ EmitOnPing

bool WebSocketSharp.Server.WebSocketBehavior.EmitOnPing
getset

Gets or sets a value indicating whether the message event is emitted when the WebSocket interface for a session receives a ping.

true if the interface emits the message event when receives a ping; otherwise, false.

The default value is false.

◆ Headers

NameValueCollection WebSocketSharp.Server.WebSocketBehavior.Headers
getprotected

Gets the HTTP headers for a session.

A NameValueCollection that contains the headers included in the WebSocket handshake request.

Exceptions
InvalidOperationExceptionThe session has not started yet.

◆ ID

string WebSocketSharp.Server.WebSocketBehavior.ID
get

Gets the unique ID of a session.

A string that represents the unique ID of the session.

null if the session has not started yet.

Implements WebSocketSharp.Server.IWebSocketSession.

◆ IgnoreExtensions

bool WebSocketSharp.Server.WebSocketBehavior.IgnoreExtensions
getset

Gets or sets a value indicating whether the WebSocket interface for a session ignores the Sec-WebSocket-Extensions header.

true if the interface ignores the extensions requested from the client; otherwise, false.

The default value is false.

◆ IsAlive

bool WebSocketSharp.Server.WebSocketBehavior.IsAlive
getprotected

Gets a value indicating whether the communication is possible for a session.

true if the communication is possible; otherwise, false.

Exceptions
InvalidOperationExceptionThe session has not started yet.

◆ OriginValidator

Func<string, bool> WebSocketSharp.Server.WebSocketBehavior.OriginValidator
getset

Gets or sets the delegate used to validate the Origin header.

A T:System.Func<string, bool> delegate.

The delegate invokes the method called when the WebSocket interface for a session validates the handshake request.

The string parameter passed to the method is the value of the Origin header or null if the header is not present.

The method must return true if the header value is valid.

null if not necessary.

The default value is null.

◆ Protocol

string WebSocketSharp.Server.WebSocketBehavior.Protocol
getset

Gets or sets the name of the WebSocket subprotocol for a session.

A string that represents the name of the subprotocol.

The value specified for a set operation must be a token defined in RFC 2616

.

The default value is an empty string.

Exceptions
InvalidOperationExceptionThe set operation is not available if the session has already started.
ArgumentExceptionThe value specified for a set operation is not a token.

◆ QueryString

NameValueCollection WebSocketSharp.Server.WebSocketBehavior.QueryString
getprotected

Gets the query string for a session.

A NameValueCollection that contains the query parameters included in the WebSocket handshake request.

An empty collection if not included.

Exceptions
InvalidOperationExceptionThe session has not started yet.

◆ ReadyState

WebSocketState WebSocketSharp.Server.WebSocketBehavior.ReadyState
getprotected

Gets the current state of the WebSocket interface for a session.

One of the WebSocketState enum values.

It indicates the current state of the interface.

Exceptions
InvalidOperationExceptionThe session has not started yet.

◆ Sessions

WebSocketSessionManager WebSocketSharp.Server.WebSocketBehavior.Sessions
getprotected

Gets the management function for the sessions in the service.

A WebSocketSessionManager that manages the sessions in the service.

Exceptions
InvalidOperationExceptionThe session has not started yet.

◆ StartTime

DateTime WebSocketSharp.Server.WebSocketBehavior.StartTime
get

Gets the time that a session has started.

A DateTime that represents the time that the session has started.

DateTime.MaxValue if the session has not started yet.

Implements WebSocketSharp.Server.IWebSocketSession.

◆ User

IPrincipal WebSocketSharp.Server.WebSocketBehavior.User
getprotected

Gets the client information for a session.

A IPrincipal instance that represents identity, authentication, and security roles for the client.

null if the client is not authenticated.

Exceptions
InvalidOperationExceptionThe session has not started yet.

◆ UserEndPoint

System.Net.IPEndPoint WebSocketSharp.Server.WebSocketBehavior.UserEndPoint
getprotected

Gets the client endpoint for a session.

A System.Net.IPEndPoint that represents the client IP address and port number.

Exceptions
InvalidOperationExceptionThe session has not started yet.

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