C# Класс WebSocketSharp.WebSocket

Implements the WebSocket interface.
The WebSocket class provides a set of methods and properties for two-way communication using the WebSocket protocol (RFC 6455).
Наследование: IDisposable
Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание
CheckParametersForClose bool
CheckParametersForClose bool
CheckPingParameter string
CheckSendParameter string
CheckSendParameter string
CheckSendParameter string
CheckSendParameters string
Close void
Close void
Close void
CreateBase64Key string
CreateResponseKey string
IDisposable void
InternalAccept void
Ping bool
Send void
Send void
WebSocket System
WebSocket System
WebSocket System
accept bool
acceptHandshake bool
checkHandshakeRequest bool
checkHandshakeResponse bool
checkIfAvailable bool
checkIfAvailable bool
checkParametersForSetCredentials bool
checkParametersForSetProxy bool
checkReceivedFrame bool
close void
close void
closeAsync void
closeAsync void
closeHandshake bool
closeHandshake bool
connect bool
createExtensions string
createHandshakeFailureResponse WebSocketSharp.HttpResponse
createHandshakeRequest HttpRequest
createHandshakeResponse WebSocketSharp.HttpResponse
customCheckHandshakeRequest bool
dequeueFromMessageEventQueue MessageEventArgs
doHandshake void
enqueueToMessageEventQueue void
error void
fatal void
fatal void
init void
message void
messagec void
messages void
open void
ping bool
processCloseFrame bool
processCookies void
processDataFrame bool
processFragmentFrame bool
processPingFrame bool
processPongFrame bool
processReceivedFrame bool
processSecWebSocketExtensionsClientHeader void
processSecWebSocketExtensionsServerHeader void
processSecWebSocketProtocolHeader void
processUnsupportedFrame bool
releaseClientResources void
releaseCommonResources void
releaseResources void
releaseServerResources void
send bool
send bool
send bool
sendAsync void
sendBytes bool
sendHandshakeRequest HttpResponse
sendHttpRequest HttpResponse
sendHttpResponse bool
sendProxyConnectRequest void
setClientStream void
startReceiving void
validateSecWebSocketAcceptHeader bool
validateSecWebSocketExtensionsClientHeader bool
validateSecWebSocketExtensionsServerHeader bool
validateSecWebSocketKeyHeader bool
validateSecWebSocketProtocolClientHeader bool
validateSecWebSocketProtocolServerHeader bool
validateSecWebSocketVersionClientHeader bool
validateSecWebSocketVersionServerHeader bool

Открытые методы

Метод Описание
Accept ( ) : void

Accepts the WebSocket handshake request.

This method is not available in a client.

AcceptAsync ( ) : void

Accepts the WebSocket handshake request asynchronously.

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

This method is not available in a client.

Close ( ) : void

Closes the WebSocket connection, and releases all associated resources.

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

Close ( CloseStatusCode code ) : void

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

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

Close ( CloseStatusCode code, string reason ) : void

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

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

Close ( ushort code ) : void

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

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

Close ( ushort code, string reason ) : void

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

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

CloseAsync ( ) : void

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

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

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

CloseAsync ( CloseStatusCode code ) : void

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

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

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

CloseAsync ( CloseStatusCode code, string reason ) : void

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

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

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

CloseAsync ( ushort code ) : void

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

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

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

CloseAsync ( ushort code, string reason ) : void

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

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

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

Connect ( ) : void

Establishes a WebSocket connection.

This method is not available in a server.

ConnectAsync ( ) : void

Establishes a WebSocket connection asynchronously.

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

This method is not available in a server.

Ping ( ) : bool

Sends a ping using the WebSocket connection.

Ping ( string message ) : bool

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

Send ( FileInfo fileInfo ) : void

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

Send ( Stream stream, int length ) : void

Sends the specified length of data from the specified stream using the WebSocket connection.

Send ( byte data ) : void

Sends the specified data using the WebSocket connection.

Send ( string data ) : void

Sends the specified data using the WebSocket connection.

SendAsync ( FileInfo fileInfo, Action completed ) : void

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

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

SendAsync ( Stream stream, int length, Action completed ) : void

Sends the specified length of data from the specified stream asynchronously using the WebSocket connection.

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

SendAsync ( byte data, Action completed ) : void

Sends the specified data asynchronously using the WebSocket connection.

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

SendAsync ( string data, Action completed ) : void

Sends the specified data asynchronously using the WebSocket connection.

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

SetCookie ( Cookie cookie ) : void

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

This method is not available in a server.

SetCredentials ( string username, string password, bool preAuth ) : void

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

This method is not available in a server.

SetProxy ( string url, string username, string password ) : void

Sets the HTTP proxy server URL to connect through, and if necessary, a pair of username and password for the proxy server authentication (Basic/Digest).

This method is not available in a server.

WebSocket ( string url ) : System

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

Приватные методы

Метод Описание
CheckParametersForClose ( CloseStatusCode code, string reason, bool client, string &message ) : bool
CheckParametersForClose ( ushort code, string reason, bool client, string &message ) : bool
CheckPingParameter ( string message, byte &bytes ) : string
CheckSendParameter ( FileInfo file ) : string
CheckSendParameter ( byte data ) : string
CheckSendParameter ( string data ) : string
CheckSendParameters ( Stream stream, int length ) : string
Close ( CloseEventArgs e, byte frameAsBytes, bool receive ) : void
Close ( WebSocketSharp.HttpResponse response ) : void
Close ( HttpStatusCode code ) : void
CreateBase64Key ( ) : string
CreateResponseKey ( string base64Key ) : string
IDisposable ( ) : void

Closes the WebSocket connection, and releases all associated resources.

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

This method closes the connection with status code 1001 (going away).

InternalAccept ( ) : void
Ping ( byte frameAsBytes, System.TimeSpan timeout ) : bool
Send ( Opcode opcode, Stream stream, Stream>.Dictionary cache ) : void
Send ( Opcode opcode, byte data, byte[]>.Dictionary cache ) : void
WebSocket ( ) : System
WebSocket ( HttpListenerWebSocketContext context, string protocol ) : System
WebSocket ( TcpListenerWebSocketContext context, string protocol ) : System
accept ( ) : bool
acceptHandshake ( ) : bool
checkHandshakeRequest ( WebSocketContext context, string &message ) : bool
checkHandshakeResponse ( WebSocketSharp.HttpResponse response, string &message ) : bool
checkIfAvailable ( bool client, bool server, bool connecting, bool open, bool closing, bool closed, string &message ) : bool
checkIfAvailable ( bool connecting, bool open, bool closing, bool closed, string &message ) : bool
checkParametersForSetCredentials ( string username, string password, string &message ) : bool
checkParametersForSetProxy ( string url, string username, string password, string &message ) : bool
checkReceivedFrame ( WebSocketFrame frame, string &message ) : bool
close ( PayloadData payloadData, bool send, bool receive, bool received ) : void
close ( ushort code, string reason ) : void
closeAsync ( PayloadData payloadData, bool send, bool receive, bool received ) : void
closeAsync ( ushort code, string reason ) : void
closeHandshake ( PayloadData payloadData, bool send, bool receive, bool received ) : bool
closeHandshake ( byte frameAsBytes, bool receive, bool received ) : bool
connect ( ) : bool
createExtensions ( ) : string
createHandshakeFailureResponse ( HttpStatusCode code ) : WebSocketSharp.HttpResponse
createHandshakeRequest ( ) : HttpRequest
createHandshakeResponse ( ) : WebSocketSharp.HttpResponse
customCheckHandshakeRequest ( WebSocketContext context, string &message ) : bool
dequeueFromMessageEventQueue ( ) : MessageEventArgs
doHandshake ( ) : void
enqueueToMessageEventQueue ( MessageEventArgs e ) : void
error ( string message, Exception exception ) : void
fatal ( string message, CloseStatusCode code ) : void
fatal ( string message, Exception exception ) : void
init ( ) : void
message ( ) : void
messagec ( MessageEventArgs e ) : void
messages ( MessageEventArgs e ) : void
open ( ) : void
ping ( byte data ) : bool
processCloseFrame ( WebSocketFrame frame ) : bool
processCookies ( CookieCollection cookies ) : void
processDataFrame ( WebSocketFrame frame ) : bool
processFragmentFrame ( WebSocketFrame frame ) : bool
processPingFrame ( WebSocketFrame frame ) : bool
processPongFrame ( WebSocketFrame frame ) : bool
processReceivedFrame ( WebSocketFrame frame ) : bool
processSecWebSocketExtensionsClientHeader ( string value ) : void
processSecWebSocketExtensionsServerHeader ( string value ) : void
processSecWebSocketProtocolHeader ( IEnumerable values ) : void
processUnsupportedFrame ( WebSocketFrame frame ) : bool
releaseClientResources ( ) : void
releaseCommonResources ( ) : void
releaseResources ( ) : void
releaseServerResources ( ) : void
send ( Fin fin, Opcode opcode, byte data, bool compressed ) : bool
send ( Opcode opcode, Stream stream ) : bool
send ( Opcode opcode, Stream stream, bool compressed ) : bool
sendAsync ( Opcode opcode, Stream stream, Action completed ) : void
sendBytes ( byte bytes ) : bool
sendHandshakeRequest ( ) : HttpResponse
sendHttpRequest ( HttpRequest request, int millisecondsTimeout ) : HttpResponse
sendHttpResponse ( HttpResponse response ) : bool
sendProxyConnectRequest ( ) : void
setClientStream ( ) : void
startReceiving ( ) : void
validateSecWebSocketAcceptHeader ( string value ) : bool
validateSecWebSocketExtensionsClientHeader ( string value ) : bool
validateSecWebSocketExtensionsServerHeader ( string value ) : bool
validateSecWebSocketKeyHeader ( string value ) : bool
validateSecWebSocketProtocolClientHeader ( string value ) : bool
validateSecWebSocketProtocolServerHeader ( string value ) : bool
validateSecWebSocketVersionClientHeader ( string value ) : bool
validateSecWebSocketVersionServerHeader ( string value ) : bool

Описание методов

Accept() публичный Метод

Accepts the WebSocket handshake request.
This method is not available in a client.
public Accept ( ) : void
Результат void

AcceptAsync() публичный Метод

Accepts the WebSocket handshake request asynchronously.

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

This method is not available in a client.

public AcceptAsync ( ) : void
Результат void

Close() публичный Метод

Closes the WebSocket connection, and releases all associated resources.
This method does nothing if the current state of the connection is Closing or Closed.
public Close ( ) : void
Результат void

Close() публичный Метод

Closes the WebSocket connection with the specified code, and releases all associated resources.
This method does nothing if the current state of the connection is Closing or Closed.
public Close ( CloseStatusCode code ) : void
code CloseStatusCode /// One of the enum values that represents /// the status code indicating the reason for the close. ///
Результат void

Close() публичный Метод

Closes the WebSocket connection with the specified code and reason, and releases all associated resources.
This method does nothing if the current state of the connection is Closing or Closed.
public Close ( CloseStatusCode code, string reason ) : void
code CloseStatusCode /// One of the enum values that represents /// the status code indicating the reason for the close. ///
reason string /// A that represents the reason for the close. /// The size must be 123 bytes or less. ///
Результат void

Close() публичный Метод

Closes the WebSocket connection with the specified code, and releases all associated resources.
This method does nothing if the current state of the connection is Closing or Closed.
public Close ( ushort code ) : void
code ushort /// A that represents the status code indicating /// the reason for the close. The status codes are defined in /// /// Section 7.4 of RFC 6455. ///
Результат void

Close() публичный Метод

Closes the WebSocket connection with the specified code and reason, and releases all associated resources.
This method does nothing if the current state of the connection is Closing or Closed.
public Close ( ushort code, string reason ) : void
code ushort /// A that represents the status code indicating /// the reason for the close. The status codes are defined in /// /// Section 7.4 of RFC 6455. ///
reason string /// A that represents the reason for the close. /// The size must be 123 bytes or less. ///
Результат void

CloseAsync() публичный Метод

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

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

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

public CloseAsync ( ) : void
Результат void

CloseAsync() публичный Метод

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

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

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

public CloseAsync ( CloseStatusCode code ) : void
code CloseStatusCode /// One of the enum values that represents /// the status code indicating the reason for the close. ///
Результат void

CloseAsync() публичный Метод

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

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

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

public CloseAsync ( CloseStatusCode code, string reason ) : void
code CloseStatusCode /// One of the enum values that represents /// the status code indicating the reason for the close. ///
reason string /// A that represents the reason for the close. /// The size must be 123 bytes or less. ///
Результат void

CloseAsync() публичный Метод

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

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

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

public CloseAsync ( ushort code ) : void
code ushort /// A that represents the status code indicating /// the reason for the close. The status codes are defined in /// /// Section 7.4 of RFC 6455. ///
Результат void

CloseAsync() публичный Метод

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

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

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

public CloseAsync ( ushort code, string reason ) : void
code ushort /// A that represents the status code indicating /// the reason for the close. The status codes are defined in /// /// Section 7.4 of RFC 6455. ///
reason string /// A that represents the reason for the close. /// The size must be 123 bytes or less. ///
Результат void

Connect() публичный Метод

Establishes a WebSocket connection.
This method is not available in a server.
public Connect ( ) : void
Результат void

ConnectAsync() публичный Метод

Establishes a WebSocket connection asynchronously.

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

This method is not available in a server.

public ConnectAsync ( ) : void
Результат void

Ping() публичный Метод

Sends a ping using the WebSocket connection.
public Ping ( ) : bool
Результат bool

Ping() публичный Метод

Sends a ping with the specified message using the WebSocket connection.
/// is . /// /// could not be UTF-8-encoded. /// /// The size of is greater than 125 bytes. ///
public Ping ( string message ) : bool
message string /// A that represents the message to send. /// The size must be 125 bytes or less in UTF-8. ///
Результат bool

Send() публичный Метод

Sends the specified file as the binary data using the WebSocket connection.
/// The current state of the connection is not Open. /// /// is . /// /// /// The file does not exist. /// /// /// -or- /// /// /// The file could not be opened. /// ///
public Send ( FileInfo fileInfo ) : void
fileInfo System.IO.FileInfo /// A that specifies a file to send. ///
Результат void

Send() публичный Метод

Sends the specified length of data from the specified stream using the WebSocket connection.
/// The current state of the connection is not Open. /// /// is . /// /// /// cannot be read. /// /// /// -or- /// /// /// is less than 1. /// /// /// -or- /// /// /// No data could be read from . /// ///
public Send ( Stream stream, int length ) : void
stream Stream /// A from which reads the binary data to send. ///
length int /// An that specifies the number of bytes to read and send. ///
Результат void

Send() публичный Метод

Sends the specified data using the WebSocket connection.
/// The current state of the connection is not Open. /// /// is . ///
public Send ( byte data ) : void
data byte /// An array of that represents the binary data to send. ///
Результат void

Send() публичный Метод

Sends the specified data using the WebSocket connection.
/// The current state of the connection is not Open. /// /// is . /// /// could not be UTF-8-encoded. ///
public Send ( string data ) : void
data string /// A that represents the text data to send. ///
Результат void

SendAsync() публичный Метод

Sends the specified file as the binary data asynchronously using the WebSocket connection.
This method does not wait for the send to be complete.
/// The current state of the connection is not Open. /// /// is . /// /// /// The file does not exist. /// /// /// -or- /// /// /// The file could not be opened. /// ///
public SendAsync ( FileInfo fileInfo, Action completed ) : void
fileInfo System.IO.FileInfo /// A that specifies a file to send. ///
completed Action /// An Action<bool> delegate that invokes the method called when /// the send is complete. A passed to this delegate will be /// true if the send has done with no error. ///
Результат void

SendAsync() публичный Метод

Sends the specified length of data from the specified stream asynchronously using the WebSocket connection.
This method does not wait for the send to be complete.
/// The current state of the connection is not Open. /// /// is . /// /// /// cannot be read. /// /// /// -or- /// /// /// is less than 1. /// /// /// -or- /// /// /// No data could be read from . /// ///
public SendAsync ( Stream stream, int length, Action completed ) : void
stream Stream /// A from which reads the binary data to send. ///
length int /// An that specifies the number of bytes to read and send. ///
completed Action /// An Action<bool> delegate that invokes the method called when /// the send is complete. A passed to this delegate will be /// true if the send has done with no error. ///
Результат void

SendAsync() публичный Метод

Sends the specified data asynchronously using the WebSocket connection.
This method does not wait for the send to be complete.
/// The current state of the connection is not Open. /// /// is . ///
public SendAsync ( byte data, Action completed ) : void
data byte /// An array of that represents the binary data to send. ///
completed Action /// An Action<bool> delegate that invokes the method called when /// the send is complete. A passed to this delegate will be /// true if the send has done with no error. ///
Результат void

SendAsync() публичный Метод

Sends the specified data asynchronously using the WebSocket connection.
This method does not wait for the send to be complete.
/// The current state of the connection is not Open. /// /// is . /// /// could not be UTF-8-encoded. ///
public SendAsync ( string data, Action completed ) : void
data string /// A that represents the text data to send. ///
completed Action /// An Action<bool> delegate that invokes the method called when /// the send is complete. A passed to this delegate will be /// true if the send has done with no error. ///
Результат void

SetCookie() публичный Метод

Sets an HTTP cookie to send with the WebSocket handshake request to the server.
This method is not available in a server.
public SetCookie ( Cookie cookie ) : void
cookie System.Net.Cookie /// A that represents a cookie to send. ///
Результат void

SetCredentials() публичный Метод

Sets a pair of username and password for the HTTP authentication (Basic/Digest).
This method is not available in a server.
public SetCredentials ( string username, string password, bool preAuth ) : void
username string /// /// A that represents the user name used to authenticate. /// /// /// If is or empty, /// the credentials will be initialized and not be sent. /// ///
password string /// A that represents the password for /// used to authenticate. ///
preAuth bool /// true if the sends the credentials for /// the Basic authentication with the first handshake request to the server; /// otherwise, false. ///
Результат void

SetProxy() публичный Метод

Sets the HTTP proxy server URL to connect through, and if necessary, a pair of username and password for the proxy server authentication (Basic/Digest).
This method is not available in a server.
public SetProxy ( string url, string username, string password ) : void
url string /// /// A that represents the HTTP proxy server URL to /// connect through. The syntax must be http://<host>[:<port>]. /// /// /// If is or empty, /// the url and credentials for the proxy will be initialized, /// and the will not use the proxy to /// connect through. /// ///
username string /// /// A that represents the user name used to authenticate. /// /// /// If is or empty, /// the credentials for the proxy will be initialized and not be sent. /// ///
password string /// A that represents the password for /// used to authenticate. ///
Результат void

WebSocket() публичный Метод

Initializes a new instance of the WebSocket class with the specified WebSocket URL and subprotocols.
/// is . /// /// /// is invalid. /// /// /// -or- /// /// /// is invalid. /// ///
public WebSocket ( string url ) : System
url string /// A that represents the WebSocket URL to connect. ///
Результат System