EGDL2 2.1
Loading...
Searching...
No Matches
WebSocketSharp.WebSocket Class Reference

Implements the WebSocket interface. More...

Inherits IDisposable.

Public Member Functions

 WebSocket (string url, params string[] protocols)
 Initializes a new instance of the WebSocket class with the specified WebSocket URL and subprotocols.
 
void Close ()
 Closes the WebSocket connection, and releases all associated resources.
 
void Close (ushort code)
 Closes the WebSocket connection with the specified ushort, and releases all associated resources.
 
void Close (CloseStatusCode code)
 Closes the WebSocket connection with the specified CloseStatusCode, and releases all associated resources.
 
void Close (ushort code, string reason)
 Closes the WebSocket connection with the specified ushort and string, and releases all associated resources.
 
void Close (CloseStatusCode code, string reason)
 Closes the WebSocket connection with the specified CloseStatusCode and string, and releases all associated resources.
 
void CloseAsync ()
 Closes the WebSocket connection asynchronously, and releases all associated resources.
 
void CloseAsync (ushort code)
 Closes the WebSocket connection asynchronously with the specified ushort, and releases all associated resources.
 
void CloseAsync (CloseStatusCode code)
 Closes the WebSocket connection asynchronously with the specified CloseStatusCode, and releases all associated resources.
 
void CloseAsync (ushort code, string reason)
 Closes the WebSocket connection asynchronously with the specified ushort and string, and releases all associated resources.
 
void CloseAsync (CloseStatusCode code, string reason)
 Closes the WebSocket connection asynchronously with the specified CloseStatusCode and string, and releases all associated resources.
 
void Connect ()
 Establishes a WebSocket connection.
 
void ConnectAsync ()
 Establishes a WebSocket connection asynchronously.
 
bool Ping ()
 Sends a Ping using the WebSocket connection.
 
bool Ping (string message)
 Sends a Ping with the specified message using the WebSocket connection.
 
void Send (byte[] data)
 Sends a binary data using the WebSocket connection.
 
void Send (FileInfo file)
 Sends the specified file as a binary data using the WebSocket connection.
 
void Send (string data)
 Sends a text data using the WebSocket connection.
 
void SendAsync (byte[] data, Action< bool > completed)
 Sends a binary data asynchronously using the WebSocket connection.
 
void SendAsync (FileInfo file, Action< bool > completed)
 Sends the specified file as a binary data asynchronously using the WebSocket connection.
 
void SendAsync (string data, Action< bool > completed)
 Sends a text data asynchronously using the WebSocket connection.
 
void SendAsync (Stream stream, int length, Action< bool > completed)
 Sends a binary data from the specified Stream asynchronously using the WebSocket connection.
 
void SetCookie (Cookie cookie)
 Sets an HTTP cookie to send with the WebSocket connection request to the server.
 
void SetCredentials (string username, string password, bool preAuth)
 Sets a pair of username and password for the HTTP authentication (Basic/Digest).
 

Properties

CompressionMethod Compression [get, set]
 Gets or sets the compression method used to compress the message on the WebSocket connection.
 
IEnumerable< CookieCookies [get]
 Gets the HTTP cookies included in the WebSocket connection request and response.
 
NetworkCredential Credentials [get]
 Gets the credentials for the HTTP authentication (Basic/Digest).
 
string Extensions [get]
 Gets the WebSocket extensions selected by the server.
 
bool IsAlive [get]
 Gets a value indicating whether the WebSocket connection is alive.
 
bool IsSecure [get]
 Gets a value indicating whether the WebSocket connection is secure.
 
Logger Log [get, set]
 Gets the logging functions.
 
string Origin [get, set]
 Gets or sets the value of the Origin header to send with the WebSocket connection request to the server.
 
string Protocol [get, set]
 Gets the WebSocket subprotocol selected by the server.
 
WebSocketState ReadyState [get]
 Gets the state of the WebSocket connection.
 
RemoteCertificateValidationCallback ServerCertificateValidationCallback [get, set]
 Gets or sets the callback used to validate the certificate supplied by the server.
 
Uri Url [get]
 Gets the WebSocket URL to connect.
 

Events

EventHandler< CloseEventArgsOnClose
 Occurs when the WebSocket connection has been closed.
 
EventHandler< ErrorEventArgsOnError
 Occurs when the WebSocket gets an error.
 
EventHandler< MessageEventArgsOnMessage
 Occurs when the WebSocket receives a message.
 
EventHandler OnOpen
 Occurs when the WebSocket connection has been established.
 

Detailed Description

Implements the WebSocket interface.

The WebSocket class provides a set of methods and properties for two-way communication using the WebSocket protocol (RFC 6455

).

Constructor & Destructor Documentation

◆ WebSocket()

WebSocketSharp.WebSocket.WebSocket ( string url,
params string[] protocols )
inline

Initializes a new instance of the WebSocket class with the specified WebSocket URL and subprotocols.

Parameters
urlA string that represents the WebSocket URL to connect.
protocolsAn array of string that contains the WebSocket subprotocols if any. Each value of protocols must be a token defined in RFC 2616.
Exceptions
ArgumentExceptionurl is invalid. -or- protocols is invalid.
ArgumentNullExceptionurl is null.

Member Function Documentation

◆ Close() [1/4]

void WebSocketSharp.WebSocket.Close ( CloseStatusCode code)
inline

Closes the WebSocket connection with the specified CloseStatusCode, and releases all associated resources.

Parameters
codeOne of the CloseStatusCode enum values, represents the status code indicating the reason for closure.

◆ Close() [2/4]

void WebSocketSharp.WebSocket.Close ( CloseStatusCode code,
string reason )
inline

Closes the WebSocket connection with the specified CloseStatusCode and string, and releases all associated resources.

This method emits a OnError event if the size of reason is greater than 123 bytes.

Parameters
codeOne of the CloseStatusCode enum values, represents the status code indicating the reason for closure.
reasonA string that represents the reason for closure.

◆ Close() [3/4]

void WebSocketSharp.WebSocket.Close ( ushort code)
inline

Closes the WebSocket connection with the specified ushort, and releases all associated resources.

This method emits a OnError event if code isn't in the allowable range of the WebSocket close status code.

Parameters
codeA ushort that represents the status code indicating the reason for closure.

◆ Close() [4/4]

void WebSocketSharp.WebSocket.Close ( ushort code,
string reason )
inline

Closes the WebSocket connection with the specified ushort and string, and releases all associated resources.

This method emits a OnError event if code isn't in the allowable range of the WebSocket close status code or the size of reason is greater than 123 bytes.

Parameters
codeA ushort that represents the status code indicating the reason for closure.
reasonA string that represents the reason for closure.

◆ CloseAsync() [1/5]

void WebSocketSharp.WebSocket.CloseAsync ( )
inline

Closes the WebSocket connection asynchronously, and releases all associated resources.

This method doesn't wait for the close to be complete.

◆ CloseAsync() [2/5]

void WebSocketSharp.WebSocket.CloseAsync ( CloseStatusCode code)
inline

Closes the WebSocket connection asynchronously with the specified CloseStatusCode, and releases all associated resources.

This method doesn't wait for the close to be complete.

Parameters
codeOne of the CloseStatusCode enum values, represents the status code indicating the reason for closure.

◆ CloseAsync() [3/5]

void WebSocketSharp.WebSocket.CloseAsync ( CloseStatusCode code,
string reason )
inline

Closes the WebSocket connection asynchronously with the specified CloseStatusCode and string, and releases all associated resources.

This method doesn't wait for the close to be complete.

This method emits a OnError event if the size of reason is greater than 123 bytes.

Parameters
codeOne of the CloseStatusCode enum values, represents the status code indicating the reason for closure.
reasonA string that represents the reason for closure.

◆ CloseAsync() [4/5]

void WebSocketSharp.WebSocket.CloseAsync ( ushort code)
inline

Closes the WebSocket connection asynchronously with the specified ushort, and releases all associated resources.

This method doesn't wait for the close to be complete.

This method emits a OnError event if code isn't in the allowable range of the WebSocket close status code.

Parameters
codeA ushort that represents the status code indicating the reason for closure.

◆ CloseAsync() [5/5]

void WebSocketSharp.WebSocket.CloseAsync ( ushort code,
string reason )
inline

Closes the WebSocket connection asynchronously with the specified ushort and string, and releases all associated resources.

This method doesn't wait for the close to be complete.

This method emits a OnError event if code isn't in the allowable range of the WebSocket close status code or the size of reason is greater than 123 bytes.

Parameters
codeA ushort that represents the status code indicating the reason for closure.
reasonA string that represents the reason for closure.

◆ ConnectAsync()

void WebSocketSharp.WebSocket.ConnectAsync ( )
inline

Establishes a WebSocket connection asynchronously.

This method doesn't wait for the connect to be complete.

◆ Ping() [1/2]

bool WebSocketSharp.WebSocket.Ping ( )
inline

Sends a Ping using the WebSocket connection.

Returns
true if the WebSocket receives a Pong to this Ping in a time; otherwise, false.

◆ Ping() [2/2]

bool WebSocketSharp.WebSocket.Ping ( string message)
inline

Sends a Ping with the specified message using the WebSocket connection.

Returns
true if the WebSocket receives a Pong to this Ping in a time; otherwise, false.
Parameters
messageA string that represents the message to send.

◆ Send() [1/3]

void WebSocketSharp.WebSocket.Send ( byte[] data)
inline

Sends a binary data using the WebSocket connection.

Parameters
dataAn array of byte that represents the binary data to send.

◆ Send() [2/3]

void WebSocketSharp.WebSocket.Send ( FileInfo file)
inline

Sends the specified file as a binary data using the WebSocket connection.

Parameters
fileA FileInfo that represents the file to send.

◆ Send() [3/3]

void WebSocketSharp.WebSocket.Send ( string data)
inline

Sends a text data using the WebSocket connection.

Parameters
dataA string that represents the text data to send.

◆ SendAsync() [1/4]

void WebSocketSharp.WebSocket.SendAsync ( byte[] data,
Action< bool > completed )
inline

Sends a binary data asynchronously using the WebSocket connection.

This method doesn't wait for the send to be complete.

Parameters
dataAn array of byte that represents the binary data to send.
completedAn Action<bool> delegate that references the method(s) called when the send is complete. A bool passed to this delegate is true if the send is complete successfully; otherwise, false.

◆ SendAsync() [2/4]

void WebSocketSharp.WebSocket.SendAsync ( FileInfo file,
Action< bool > completed )
inline

Sends the specified file as a binary data asynchronously using the WebSocket connection.

This method doesn't wait for the send to be complete.

Parameters
fileA FileInfo that represents the file to send.
completedAn Action<bool> delegate that references the method(s) called when the send is complete. A bool passed to this delegate is true if the send is complete successfully; otherwise, false.

◆ SendAsync() [3/4]

void WebSocketSharp.WebSocket.SendAsync ( Stream stream,
int length,
Action< bool > completed )
inline

Sends a binary data from the specified Stream asynchronously using the WebSocket connection.

This method doesn't wait for the send to be complete.

Parameters
streamA Stream from which contains the binary data to send.
lengthAn int that represents the number of bytes to send.
completedAn Action<bool> delegate that references the method(s) called when the send is complete. A bool passed to this delegate is true if the send is complete successfully; otherwise, false.

◆ SendAsync() [4/4]

void WebSocketSharp.WebSocket.SendAsync ( string data,
Action< bool > completed )
inline

Sends a text data asynchronously using the WebSocket connection.

This method doesn't wait for the send to be complete.

Parameters
dataA string that represents the text data to send.
completedAn Action<bool> delegate that references the method(s) called when the send is complete. A bool passed to this delegate is true if the send is complete successfully; otherwise, false.

◆ SetCookie()

void WebSocketSharp.WebSocket.SetCookie ( Cookie cookie)
inline

Sets an HTTP cookie to send with the WebSocket connection request to the server.

Parameters
cookieA Cookie that represents the cookie to send.

◆ SetCredentials()

void WebSocketSharp.WebSocket.SetCredentials ( string username,
string password,
bool preAuth )
inline

Sets a pair of username and password for the HTTP authentication (Basic/Digest).

Parameters
usernameA string that represents the user name used to authenticate.
passwordA string that represents the password for username used to authenticate.
preAuthtrue if the WebSocket sends the Basic authentication credentials with the first connection request to the server; otherwise, false.

Property Documentation

◆ Compression

CompressionMethod WebSocketSharp.WebSocket.Compression
getset

Gets or sets the compression method used to compress the message on the WebSocket connection.

One of the CompressionMethod enum values, indicates the compression method used to compress the message. The default value is CompressionMethod.None.

◆ Cookies

IEnumerable<Cookie> WebSocketSharp.WebSocket.Cookies
get

Gets the HTTP cookies included in the WebSocket connection request and response.

An IEnumerable<Cookie> instance that provides an enumerator which supports the iteration over the collection of the cookies.

◆ Credentials

NetworkCredential WebSocketSharp.WebSocket.Credentials
get

Gets the credentials for the HTTP authentication (Basic/Digest).

A NetworkCredential that represents the credentials for the HTTP authentication. The default value is null.

◆ Extensions

string WebSocketSharp.WebSocket.Extensions
get

Gets the WebSocket extensions selected by the server.

A string that represents the extensions if any. The default value is String.Empty.

◆ IsAlive

bool WebSocketSharp.WebSocket.IsAlive
get

Gets a value indicating whether the WebSocket connection is alive.

true if the connection is alive; otherwise, false.

◆ IsSecure

bool WebSocketSharp.WebSocket.IsSecure
get

Gets a value indicating whether the WebSocket connection is secure.

true if the connection is secure; otherwise, false.

◆ Log

Logger WebSocketSharp.WebSocket.Log
getset

Gets the logging functions.

The default logging level is LogLevel.Error. If you would like to change it, you should set the Log.Level property to any of the LogLevel enum values.

A Logger that provides the logging functions.

◆ Origin

string WebSocketSharp.WebSocket.Origin
getset

Gets or sets the value of the Origin header to send with the WebSocket connection request to the server.

The WebSocket sends the Origin header if this property has any.

A string that represents the value of the HTTP Origin header

to send. The default value is null.

The Origin header has the following syntax: <scheme>://<host>[:<port>]

◆ Protocol

string WebSocketSharp.WebSocket.Protocol
getset

Gets the WebSocket subprotocol selected by the server.

A string that represents the subprotocol if any. The default value is String.Empty.

◆ ReadyState

WebSocketState WebSocketSharp.WebSocket.ReadyState
get

Gets the state of the WebSocket connection.

One of the WebSocketState enum values, indicates the state of the WebSocket connection. The default value is WebSocketState.Connecting.

◆ ServerCertificateValidationCallback

RemoteCertificateValidationCallback WebSocketSharp.WebSocket.ServerCertificateValidationCallback
getset

Gets or sets the callback used to validate the certificate supplied by the server.

If the value of this property is null, the validation does nothing with the server certificate, always returns valid.

A RemoteCertificateValidationCallback delegate that references the method(s) used to validate the server certificate. The default value is null.

◆ Url

Uri WebSocketSharp.WebSocket.Url
get

Gets the WebSocket URL to connect.

A Uri that represents the WebSocket URL to connect.


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