My Project
|
Implements the WebSocket interface. More...
Public Member Functions | |
WebSocket (string url, params string[] protocols) | |
Initializes a new instance of the WebSocket class with the specified URL and optionally subprotocols. | |
void | Close () |
Closes the connection. | |
void | Close (ushort code) |
Closes the connection with the specified code. | |
void | Close (CloseStatusCode code) |
Closes the connection with the specified code. | |
void | Close (ushort code, string reason) |
Closes the connection with the specified code and reason. | |
void | Close (CloseStatusCode code, string reason) |
Closes the connection with the specified code and reason. | |
void | CloseAsync () |
Closes the connection asynchronously. | |
void | CloseAsync (ushort code) |
Closes the connection asynchronously with the specified code. | |
void | CloseAsync (CloseStatusCode code) |
Closes the connection asynchronously with the specified code. | |
void | CloseAsync (ushort code, string reason) |
Closes the connection asynchronously with the specified code and reason. | |
void | CloseAsync (CloseStatusCode code, string reason) |
Closes the connection asynchronously with the specified code and reason. | |
void | Connect () |
Establishes a connection. | |
void | ConnectAsync () |
Establishes a connection asynchronously. | |
bool | Ping () |
Sends a ping to the remote endpoint. | |
bool | Ping (string message) |
Sends a ping with the specified message to the remote endpoint. | |
void | Send (byte[] data) |
Sends the specified data to the remote endpoint. | |
void | Send (FileInfo fileInfo) |
Sends the specified file to the remote endpoint. | |
void | Send (string data) |
Sends the specified data to the remote endpoint. | |
void | Send (Stream stream, int length) |
Sends the data from the specified stream instance to the remote endpoint. | |
void | SendAsync (byte[] data, Action< bool > completed) |
Sends the specified data to the remote endpoint asynchronously. | |
void | SendAsync (FileInfo fileInfo, Action< bool > completed) |
Sends the specified file to the remote endpoint asynchronously. | |
void | SendAsync (string data, Action< bool > completed) |
Sends the specified data to the remote endpoint asynchronously. | |
void | SendAsync (Stream stream, int length, Action< bool > completed) |
Sends the data from the specified stream instance to the remote endpoint asynchronously. | |
void | SetCookie (Cookie cookie) |
Sets an HTTP cookie to send with the handshake request. | |
void | SetCredentials (string username, string password, bool preAuth) |
Sets the credentials for the HTTP authentication (Basic/Digest). | |
void | SetProxy (string url, string username, string password) |
Sets the URL of the HTTP proxy server through which to connect and the credentials for the HTTP proxy authentication (Basic/Digest). | |
Properties | |
CompressionMethod | Compression [get, set] |
Gets or sets the compression method used to compress a message. | |
IEnumerable< Cookie > | Cookies [get] |
Gets the HTTP cookies included in the handshake request/response. | |
NetworkCredential | Credentials [get] |
Gets the credentials for the HTTP authentication (Basic/Digest). | |
bool | EmitOnPing [get, set] |
Gets or sets a value indicating whether the message event is emitted when the interface receives a ping. | |
bool | EnableRedirection [get, set] |
Gets or sets a value indicating whether the URL redirection for the handshake request is allowed. | |
string | Extensions [get] |
Gets the extensions selected by the server. | |
bool | IsAlive [get] |
Gets a value indicating whether the communication is possible. | |
bool | IsSecure [get] |
Gets a value indicating whether the connection is secure. | |
Logger | Log [get, set] |
Gets the logging function. | |
string | Origin [get, set] |
Gets or sets the value of the HTTP Origin header to send with the handshake request. | |
string | Protocol [get, set] |
Gets the name of subprotocol selected by the server. | |
WebSocketState | ReadyState [get] |
Gets the current state of the interface. | |
ClientSslConfiguration | SslConfiguration [get] |
Gets the configuration for secure connection. | |
Uri | Url [get] |
Gets the URL to which to connect. | |
TimeSpan | WaitTime [get, set] |
Gets or sets the time to wait for the response to the ping or close. | |
Events | |
EventHandler< CloseEventArgs > | OnClose |
Occurs when the connection has been closed. | |
EventHandler< ErrorEventArgs > | OnError |
Occurs when the interface gets an error. | |
EventHandler< MessageEventArgs > | OnMessage |
Occurs when the interface receives a message. | |
EventHandler | OnOpen |
Occurs when the connection has been established. | |
Implements the WebSocket interface.
This class provides a set of methods and properties for two-way communication using the WebSocket protocol.
The WebSocket protocol is defined in RFC 6455
.
|
inline |
Initializes a new instance of the WebSocket class with the specified URL and optionally subprotocols.
url | A string that specifies the URL to which to connect. The scheme of the URL must be ws or wss. The new instance uses a secure connection if the scheme is wss. |
protocols | An array of string that specifies the names of the subprotocols if necessary. Each value of the array must be a token defined in RFC 2616. |
ArgumentNullException | url is null . |
ArgumentException | url is an empty string. -or- url is an invalid WebSocket URL string. -or- protocols contains a value that is not a token. -or- protocols contains a value twice. |
|
inline |
Closes the connection.
This method does nothing if the current state of the interface is Closing or Closed.
|
inline |
Closes the connection with the specified code.
This method does nothing if the current state of the interface is Closing or Closed.
code | One of the CloseStatusCode enum values. It specifies the status code indicating the reason for the close. |
ArgumentException | code is CloseStatusCode.ServerError. It cannot be used by a client. -or- code is CloseStatusCode.MandatoryExtension. It cannot be used by a server. |
|
inline |
Closes the connection with the specified code and reason.
This method does nothing if the current state of the interface is Closing or Closed.
code | One of the CloseStatusCode enum values. It specifies the status code indicating the reason for the close. |
reason | A string that specifies the reason for the close. Its size must be 123 bytes or less in UTF-8. |
ArgumentException | code is CloseStatusCode.ServerError. It cannot be used by a client. -or- code is CloseStatusCode.MandatoryExtension. It cannot be used by a server. -or- code is CloseStatusCode.NoStatus and reason is specified. -or- reason could not be UTF-8-encoded. |
ArgumentOutOfRangeException | The size of reason is greater than 123 bytes. |
|
inline |
Closes the connection with the specified code.
This method does nothing if the current state of the interface is Closing or Closed.
code | A ushort that specifies the status code indicating the reason for the close. The status codes are defined in Section 7.4of RFC 6455. |
ArgumentOutOfRangeException | code is less than 1000 or greater than 4999. |
ArgumentException | code is 1011 (server error). It cannot be used by a client. -or- code is 1010 (mandatory extension). It cannot be used by a server. |
|
inline |
Closes the connection with the specified code and reason.
This method does nothing if the current state of the interface is Closing or Closed.
code | A ushort that specifies the status code indicating the reason for the close. The status codes are defined in Section 7.4of RFC 6455. |
reason | A string that specifies the reason for the close. Its size must be 123 bytes or less in UTF-8. |
ArgumentOutOfRangeException | code is less than 1000 or greater than 4999. -or- The size of reason is greater than 123 bytes. |
ArgumentException | code is 1011 (server error). It cannot be used by a client. -or- code is 1010 (mandatory extension). It cannot be used by a server. -or- code is 1005 (no status) and reason is specified. -or- reason could not be UTF-8-encoded. |
|
inline |
Closes the connection asynchronously.
This method does not wait for the close to be complete.
This method does nothing if the current state of the interface is Closing or Closed.
|
inline |
Closes the connection asynchronously with the specified code.
This method does not wait for the close to be complete.
This method does nothing if the current state of the interface is Closing or Closed.
code | One of the CloseStatusCode enum values. It specifies the status code indicating the reason for the close. |
ArgumentException | code is CloseStatusCode.ServerError. It cannot be used by a client. -or- code is CloseStatusCode.MandatoryExtension. It cannot be used by a server. |
|
inline |
Closes the connection 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 interface is Closing or Closed.
code | One of the CloseStatusCode enum values. It specifies the status code indicating the reason for the close. |
reason | A string that specifies the reason for the close. Its size must be 123 bytes or less in UTF-8. |
ArgumentException | code is CloseStatusCode.ServerError. It cannot be used by a client. -or- code is CloseStatusCode.MandatoryExtension. It cannot be used by a server. -or- code is CloseStatusCode.NoStatus and reason is specified. -or- reason could not be UTF-8-encoded. |
ArgumentOutOfRangeException | The size of reason is greater than 123 bytes. |
|
inline |
Closes the connection asynchronously with the specified code.
This method does not wait for the close to be complete.
This method does nothing if the current state of the interface is Closing or Closed.
code | A ushort that specifies the status code indicating the reason for the close. The status codes are defined in Section 7.4of RFC 6455. |
ArgumentOutOfRangeException | code is less than 1000 or greater than 4999. |
ArgumentException | code is 1011 (server error). It cannot be used by a client. -or- code is 1010 (mandatory extension). It cannot be used by a server. |
|
inline |
Closes the connection 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 interface is Closing or Closed.
code | A ushort that specifies the status code indicating the reason for the close. The status codes are defined in Section 7.4of RFC 6455. |
reason | A string that specifies the reason for the close. Its size must be 123 bytes or less in UTF-8. |
ArgumentOutOfRangeException | code is less than 1000 or greater than 4999. -or- The size of reason is greater than 123 bytes. |
ArgumentException | code is 1011 (server error). It cannot be used by a client. -or- code is 1010 (mandatory extension). It cannot be used by a server. -or- code is 1005 (no status) and reason is specified. -or- reason could not be UTF-8-encoded. |
|
inline |
Establishes a connection.
This method does nothing if the current state of the interface is Connecting or Open.
InvalidOperationException | The interface is not for the client. -or- A series of reconnecting has failed. |
|
inline |
Establishes a connection asynchronously.
This method does not wait for the connect process to be complete.
This method does nothing if the current state of the interface is Connecting or Open.
InvalidOperationException | The interface is not for the client. -or- A series of reconnecting has failed. |
|
inline |
Sends a ping to the remote endpoint.
true
if the send has successfully done and a pong has been received within a time; otherwise, false
.
|
inline |
Sends a ping with the specified message to the remote endpoint.
true
if the send has successfully done and a pong has been received within a time; otherwise, false
. message | A string that specifies the message to send. Its size must be 125 bytes or less in UTF-8. |
ArgumentException | message could not be UTF-8-encoded. |
ArgumentOutOfRangeException | The size of message is greater than 125 bytes. |
|
inline |
Sends the specified data to the remote endpoint.
data | An array of byte that specifies the binary data to send. |
InvalidOperationException | The current state of the interface is not Open. |
ArgumentNullException | data is null . |
|
inline |
Sends the specified file to the remote endpoint.
fileInfo | A FileInfo that specifies the file to send. The file is sent as the binary data. |
InvalidOperationException | The current state of the interface is not Open. |
ArgumentNullException | fileInfo is null . |
ArgumentException | The file does not exist. -or- The file could not be opened. |
|
inline |
Sends the data from the specified stream instance to the remote endpoint.
stream | A Stream instance from which to read the data to send. The data is sent as the binary data. |
length | An int that specifies the number of bytes to send. |
InvalidOperationException | The current state of the interface is not Open. |
ArgumentNullException | stream is null . |
ArgumentException | stream cannot be read. -or- length is less than 1. -or- No data could be read from stream . |
|
inline |
Sends the specified data to the remote endpoint.
data | A string that specifies the text data to send. |
InvalidOperationException | The current state of the interface is not Open. |
ArgumentNullException | data is null . |
ArgumentException | data could not be UTF-8-encoded. |
|
inline |
Sends the specified data to the remote endpoint asynchronously.
This method does not wait for the send to be complete.
data | An array of byte that specifies the binary data to send. |
completed | An 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. |
InvalidOperationException | The current state of the interface is not Open. |
ArgumentNullException | data is null . |
|
inline |
Sends the specified file to the remote endpoint asynchronously.
This method does not wait for the send to be complete.
fileInfo | A FileInfo that specifies the file to send. The file is sent as the binary data. |
completed | An 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. |
InvalidOperationException | The current state of the interface is not Open. |
ArgumentNullException | fileInfo is null . |
ArgumentException | The file does not exist. -or- The file could not be opened. |
|
inline |
Sends the data from the specified stream instance to the remote endpoint asynchronously.
This method does not wait for the send to be complete.
stream | A Stream instance from which to read the data to send. The data is sent as the binary data. |
length | An int that specifies the number of bytes to send. |
completed | An 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. |
InvalidOperationException | The current state of the interface is not Open. |
ArgumentNullException | stream is null . |
ArgumentException | stream cannot be read. -or- length is less than 1. -or- No data could be read from stream . |
|
inline |
Sends the specified data to the remote endpoint asynchronously.
This method does not wait for the send to be complete.
data | A string that specifies the text data to send. |
completed | An 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. |
InvalidOperationException | The current state of the interface is not Open. |
ArgumentNullException | data is null . |
ArgumentException | data could not be UTF-8-encoded. |
|
inline |
Sets an HTTP cookie to send with the handshake request.
This method works if the current state of the interface is New or Closed.
cookie | A Cookie that specifies the cookie to send. |
InvalidOperationException | The interface is not for the client. |
ArgumentNullException | cookie is null . |
|
inline |
Sets the credentials for the HTTP authentication (Basic/Digest).
This method works if the current state of the interface is New or Closed.
username | A string that specifies the username associated with the credentials. null or an empty string if initializes the credentials. |
password | A string that specifies the password for the username associated with the credentials. null or an empty string if not necessary. |
preAuth | A bool: true if sends the credentials for the Basic authentication in advance with the first handshake request; otherwise, false . |
InvalidOperationException | The interface is not for the client. |
ArgumentException | username contains an invalid character. -or- password contains an invalid character. |
|
inline |
Sets the URL of the HTTP proxy server through which to connect and the credentials for the HTTP proxy authentication (Basic/Digest).
This method works if the current state of the interface is New or Closed.
url | A string that specifies the URL of the proxy server through which to connect. The syntax is http://<host>[:<port>]. null or an empty string if initializes the URL and the credentials. |
username | A string that specifies the username associated with the credentials. null or an empty string if the credentials are not necessary. |
password | A string that specifies the password for the username associated with the credentials. null or an empty string if not necessary. |
InvalidOperationException | The interface is not for the client. |
ArgumentException | url is not an absolute URI string. -or- The scheme of url is not http. -or- url includes the path segments. -or- username contains an invalid character. -or- password contains an invalid character. |
|
getset |
Gets or sets the compression method used to compress a message.
The set operation works if the current state of the interface is New or Closed.
One of the CompressionMethod enum values.
It indicates the compression method used to compress a message.
The default value is CompressionMethod.None.
InvalidOperationException | The set operation is not available if the interface is not for the client. |
|
get |
Gets the HTTP cookies included in the handshake request/response.
An T:System.Collections.Generic.IEnumerable<WebSocketSharp.Net.Cookie> instance.
It provides an enumerator which supports the iteration over the collection of the cookies.
|
get |
Gets the credentials for the HTTP authentication (Basic/Digest).
A NetworkCredential that represents the credentials used to authenticate the client.
The default value is null
.
|
getset |
Gets or sets a value indicating whether the message event is emitted when the interface receives a ping.
true
if the interface emits the message event when receives a ping; otherwise, false
.
The default value is false
.
|
getset |
Gets or sets a value indicating whether the URL redirection for the handshake request is allowed.
The set operation works if the current state of the interface is New or Closed.
true
if the interface allows the URL redirection for the handshake request; otherwise, false
.
The default value is false
.
InvalidOperationException | The set operation is not available if the interface is not for the client. |
|
get |
Gets the extensions selected by the server.
A string that represents a list of the extensions negotiated between the client and server.
An empty string if not specified or selected.
|
get |
Gets a value indicating whether the communication is possible.
true
if the communication is possible; otherwise, false
.
|
get |
Gets a value indicating whether the connection is secure.
true
if the connection is secure; otherwise, false
.
|
getset |
Gets the logging function.
The default logging level is LogLevel.Error.
A Logger that provides the logging function.
|
getset |
Gets or sets the value of the HTTP Origin header to send with the handshake request.
The HTTP Origin header is defined in Section 7 of RFC 6454
.
The interface sends the Origin header if this property has any.
The set operation works if the current state of the interface is New or Closed.
A string that represents the value of the Origin header to send.
The syntax is <scheme>://<host>[:<port>].
The default value is null
.
InvalidOperationException | The set operation is not available if the interface is not for the client. |
ArgumentException | The value specified for a set operation is not an absolute URI string. -or- The value specified for a set operation includes the path segments. |
|
getset |
Gets the name of subprotocol selected by the server.
A string that will be one of the names of subprotocols specified by client.
An empty string if not specified or selected.
|
get |
Gets the current state of the interface.
One of the WebSocketState enum values.
It indicates the current state of the interface.
The default value is WebSocketState.New.
|
get |
Gets the configuration for secure connection.
The configuration is used when the interface attempts to connect, so it must be configured before any connect method is called.
A ClientSslConfiguration that represents the configuration used to establish a secure connection.
InvalidOperationException | The interface is not for the client. -or- The interface does not use a secure connection. |
|
get |
Gets the URL to which to connect.
A Uri that represents the URL to which to connect.
Also it represents the URL requested by the client if the interface is for the server.
|
getset |
Gets or sets the time to wait for the response to the ping or close.
The set operation works if the current state of the interface is New or Closed.
A TimeSpan that represents the time to wait for the response.
The default value is the same as 5 seconds if the interface is for the client.
ArgumentOutOfRangeException | The value specified for a set operation is zero or less. |