SkyWay Unity SDK
公式APIリファレンス
|
Implements the WebSocket interface. [詳解]
公開メンバ関数 | |
WebSocket (string url, Dictionary< string, string > customHeaders, 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 status code. | |
void | Close (CloseStatusCode code) |
Closes the connection with the specified status code. | |
void | Close (ushort code, string reason) |
Closes the connection with the specified status code and reason. | |
void | Close (CloseStatusCode code, string reason) |
Closes the connection with the specified status code and reason. | |
void | CloseAsync () |
Closes the connection asynchronously. | |
void | CloseAsync (ushort code) |
Closes the connection asynchronously with the specified status code. | |
void | CloseAsync (CloseStatusCode code) |
Closes the connection asynchronously with the specified status code. | |
void | CloseAsync (ushort code, string reason) |
Closes the connection asynchronously with the specified status code and reason. | |
void | CloseAsync (CloseStatusCode code, string reason) |
Closes the connection asynchronously with the specified status 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 or response. | |
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). | |
void | SetUserHeader (string name, string value) |
Sets a user header to send with the handshake request or response. | |
プロパティ | |
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 interface emits the message event when it 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. | |
NameValueCollection | HandshakeResponseHeaders [get] |
Gets the HTTP headers included in the handshake response. | |
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. | |
bool | NoDelay [get, set] |
Gets or sets a value indicating whether the underlying TCP socket disables a delay when send or receive buffer is not full. | |
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. | |
イベント | |
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. |
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. |
ArgumentNullException | url is null . |
|
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 status 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 an undefined enum value. -or- 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 status 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 an undefined enum value. -or- 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 status 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. |
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. |
ArgumentOutOfRangeException | code is less than 1000 or greater than 4999. |
|
inline |
Closes the connection with the specified status 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. |
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. |
ArgumentOutOfRangeException | code is less than 1000 or greater than 4999. -or- The size of reason is greater than 123 bytes. |
|
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 status 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 an undefined enum value. -or- 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 status 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 an undefined enum value. -or- 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 status 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. |
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. |
ArgumentOutOfRangeException | code is less than 1000 or greater than 4999. |
|
inline |
Closes the connection asynchronously with the specified status 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. |
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. |
ArgumentOutOfRangeException | code is less than 1000 or greater than 4999. -or- The size of reason is greater than 123 bytes. |
|
inline |
Establishes a connection.
This method does nothing when the current state of the interface is Connecting or Open.
InvalidOperationException | The Connect method is not available if the interface is not for the client. -or- The Connect method is not available if 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 when the current state of the interface is Connecting or Open.
InvalidOperationException | The ConnectAsync method is not available if the interface is not for the client. -or- The ConnectAsync method is not available if 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. |
ArgumentNullException | data is null . |
InvalidOperationException | The Send method is not available when the current state of the interface is not Open. |
|
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. |
ArgumentException | The file does not exist. -or- The file could not be opened. |
ArgumentNullException | fileInfo is null . |
InvalidOperationException | The Send method is not available when the current state of the interface is not Open. |
|
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. |
ArgumentException | stream cannot be read. -or- length is less than 1. -or- No data could be read from stream . |
ArgumentNullException | stream is null . |
InvalidOperationException | The Send method is not available when the current state of the interface is not Open. |
|
inline |
Sends the specified data to the remote endpoint.
data | A string that specifies the text data to send. |
ArgumentException | data could not be UTF-8-encoded. |
ArgumentNullException | data is null . |
InvalidOperationException | The Send method is not available when the current state of the interface is not Open. |
|
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. It specifies the delegate called when the send is complete. The bool parameter passed to the delegate is true if the send has successfully done; otherwise, false . null if not necessary. |
ArgumentNullException | data is null . |
InvalidOperationException | The SendAsync method is not available when the current state of the interface is not Open. |
|
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. It specifies the delegate called when the send is complete. The bool parameter passed to the delegate is true if the send has successfully done; otherwise, false . null if not necessary. |
ArgumentException | The file does not exist. -or- The file could not be opened. |
ArgumentNullException | fileInfo is null . |
InvalidOperationException | The SendAsync method is not available when the current state of the interface is not Open. |
|
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. It specifies the delegate called when the send is complete. The bool parameter passed to the delegate is true if the send has successfully done; otherwise, false . null if not necessary. |
ArgumentException | stream cannot be read. -or- length is less than 1. -or- No data could be read from stream . |
ArgumentNullException | stream is null . |
InvalidOperationException | The SendAsync method is not available when the current state of the interface is not Open. |
|
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. It specifies the delegate called when the send is complete. The bool parameter passed to the delegate is true if the send has successfully done; otherwise, false . null if not necessary. |
ArgumentException | data could not be UTF-8-encoded. |
ArgumentNullException | data is null . |
InvalidOperationException | The SendAsync method is not available when the current state of the interface is not Open. |
|
inline |
Sets an HTTP cookie to send with the handshake request or response.
cookie | A Cookie that specifies the cookie to send. |
ArgumentNullException | cookie is null . |
InvalidOperationException | The SetCookie method is not available when the current state of the interface is neither New nor Closed. |
|
inline |
Sets the credentials for the HTTP authentication (Basic/Digest).
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 . |
ArgumentException | username contains an invalid character. -or- password contains an invalid character. |
InvalidOperationException | The SetCredentials method is not available if the interface is not for the client. -or- The SetCredentials method is not available when the current state of the interface is neither New nor Closed. |
|
inline |
Sets the URL of the HTTP proxy server through which to connect and the credentials for the HTTP proxy authentication (Basic/Digest).
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. |
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. |
InvalidOperationException | The SetProxy method is not available if the interface is not for the client. -or- The SetProxy method is not available when the current state of the interface is neither New nor Closed. |
|
inline |
Sets a user header to send with the handshake request or response.
name | A string that specifies the name of the header to set. |
value | A string that specifies the value of the header to set. |
ArgumentException | name is an empty string. -or- name is a string of spaces. -or- name contains an invalid character. -or- value contains an invalid character. -or- name is a restricted header name. |
ArgumentNullException | name is null . |
ArgumentOutOfRangeException | The length of value is greater than 65,535 characters. |
InvalidOperationException | The SetUserHeader method is not available when the current state of the interface is neither New nor Closed. -or- The SetUserHeader method is not available if the interface does not allow the header type. |
|
getset |
Gets or sets the compression method used to compress a message.
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. -or- The set operation is not available when the current state of the interface is neither New nor Closed. |
|
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 interface emits the message event when it receives a ping.
true
if the interface emits the message event when it receives a ping; otherwise, false
.
The default value is false
.
InvalidOperationException | The set operation is not available when the current state of the interface is neither New nor Closed. |
|
getset |
Gets or sets a value indicating whether the URL redirection for the handshake request is allowed.
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. -or- The set operation is not available when the current state of the interface is neither New nor Closed. |
|
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 the HTTP headers included in the handshake response.
A NameValueCollection that contains the headers included in the handshake response.
InvalidOperationException | The get operation is not available if the interface is not for the client. -or- The get operation is not available when the current state of the interface is New or Connecting. |
|
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.
InvalidOperationException | The get operation is not available if the interface is not for the client. |
|
getset |
Gets or sets a value indicating whether the underlying TCP socket disables a delay when send or receive buffer is not full.
true
if the delay is disabled; otherwise, false
.
The default value is false
.
InvalidOperationException | The set operation is not available when the current state of the interface is neither New nor Closed. |
|
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.
A string that represents the value of the Origin header to send.
The syntax is <scheme>://<host>[:<port>].
The default value is null
.
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. |
InvalidOperationException | The set operation is not available if the interface is not for the client. -or- The set operation is not available when the current state of the interface is neither New nor Closed. |
|
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 get operation is not available if the interface is not for the client. -or- The get operation is not available if 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.
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. |
InvalidOperationException | The set operation is not available when the current state of the interface is neither New nor Closed. |