# WebSocketSharp.WebSocket

websocket-sharp : WebSocketSharp Namespace

# WebSocket Class

Implements the WebSocket interface.

## Syntax

public class WebSocket : IDisposable

## Remarks

The WebSocket class provides methods and properties for two-way communication using the WebSocket protocol (RFC 6455).

## Requirements

Namespace: WebSocketSharp
Assembly: websocket-sharp (in websocket-sharp.dll)

## Members

See Also: Inherited members from object.

## Public Constructors

| WebSocket (string, params string[]) | Initializes a new instance of the WebSocketSharp.WebSocket class with the specified WebSocket URL and subprotocols.
| WebSocket (string, EventHandler, EventHandler<MessageEventArgs>, EventHandler<ErrorEventArgs>, EventHandler<CloseEventArgs>, params string[]) | Initializes a new instance of the WebSocketSharp.WebSocket class with the specified WebSocket URL, OnOpen, OnMessage, OnError, OnClose event handlers and subprotocols.

## Public Properties

[read-only] | Extensions | string . Gets the extensions selected by the server.
[read-only] | IsAlive | bool . Gets a value indicating whether a connection is alive.
[read-only] | IsSecure | bool . Gets a value indicating whether a connection is secure.
[read-only] | Protocol | string . Gets the subprotocol selected by the server.
[read-only] | ReadyState | WsState . Gets the state of the connection.
[read-only] | Url | Uri . Gets the WebSocket URL.

## Public Methods

Close ()

> Closes the WebSocket connection and releases all associated resources.

Close (ushort)

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

Close (CloseStatusCode)

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

Close (ushort, string)

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

Close (CloseStatusCode, string)

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

Connect ()

> Establishes a WebSocket connection.

Dispose ()

> Closes the WebSocket connection and releases all associated resources.

Ping () : bool

> Pings using the WebSocket connection.

Ping (string) : bool

> Pings with the specified message using the WebSocket connection.

Send (byte[])

> Sends a binary data using the WebSocket connection.

Send (System.IO.FileInfo)

> Sends a binary data using the WebSocket connection.

Send (string)

> Sends a text data using the WebSocket connection.

SendAsync (byte[], Action)

> Sends a binary data asynchronously using the WebSocket connection.

SendAsync (System.IO.FileInfo, Action)

> Sends a binary data asynchronously using the WebSocket connection.

SendAsync (string, Action)

> Sends a text data asynchronously using the WebSocket connection.

## Public Events

| OnClose | Occurs when the WebSocketSharp.WebSocket receives a Close frame or the Close method is called.
| OnError | Occurs when the WebSocketSharp.WebSocket gets an error.
| OnMessage | Occurs when the WebSocketSharp.WebSocket receives a data frame.
| OnOpen | Occurs when the WebSocket connection has been established.

## Extension Methods

static

IsNull<T> (this T) : bool

> Determines whether the specified object is `null`.

static

IsNullDo<T> (this T, Action) : bool

> Determines whether the specified object is `null`. And invokes the specified Action delegate if the specified object is `null`.

## Member Details

### WebSocket Constructor

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

> ## Syntax

> public WebSocket (string url, params string[] protocols)

> #### Parameters

> > url
> >   A string that contains a WebSocket URL.
> > protocols
> >   An array of string that contains the WebSocket subprotocols if any.

> #### Exceptions

> > Type | Reason
> > --- | ---
> > ArgumentNullException | url is `null`.
> > ArgumentException | url is not valid WebSocket URL.

> ## Remarks

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### WebSocket Constructor

> Initializes a new instance of the WebSocketSharp.WebSocket class with the specified WebSocket URL, OnOpen, OnMessage, OnError, OnClose event handlers and subprotocols.

> ## Syntax

> public WebSocket (string url, EventHandler onOpen, EventHandler<MessageEventArgs> onMessage, EventHandler<ErrorEventArgs> onError, EventHandler<CloseEventArgs> onClose, params string[] protocols)

> #### Parameters

> > url
> >   A string that contains a WebSocket URL.
> > onOpen
> >   An WebSocket.OnOpen event handler.
> > onMessage
> >   An WebSocket.OnMessage event handler.
> > onError
> >   An WebSocket.OnError event handler.
> > onClose
> >   An WebSocket.OnClose event handler.
> > protocols
> >   An array of string that contains the WebSocket subprotocols if any.

> #### Exceptions

> > Type | Reason
> > --- | ---
> > ArgumentNullException | url is `null`.
> > ArgumentException | url is not valid WebSocket URL.

> ## Remarks

> This constructor initializes a new instance of the WebSocketSharp.WebSocket class and establishes a WebSocket connection.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Close Method

> Closes the WebSocket connection and releases all associated resources.

> ## Syntax

> public void Close ()

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Close Method

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

> ## Syntax

> public void Close (ushort code)

> #### Parameters

> > code
> >   A ushort that contains a status code indicating the reason for closure.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Close Method

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

> ## Syntax

> public void Close (CloseStatusCode code)

> #### Parameters

> > code
> >   One of the WebSocketSharp.CloseStatusCode values that contains a status code indicating the reason for closure.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Close Method

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

> ## Syntax

> public void Close (ushort code, string reason)

> #### Parameters

> > code
> >   A ushort that contains a status code indicating the reason for closure.
> > reason
> >   A string that contains the reason for closure.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Close Method

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

> ## Syntax

> public void Close (CloseStatusCode code, string reason)

> #### Parameters

> > code
> >   One of the WebSocketSharp.CloseStatusCode values that contains a status code indicating the reason for closure.
> > reason
> >   A string that contains the reason for closure.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Connect Method

> Establishes a WebSocket connection.

> ## Syntax

> public void Connect ()

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Dispose Method

> Closes the WebSocket connection and releases all associated resources.

> ## Syntax

> public void Dispose ()

> ## Remarks

> This method closes the WebSocket connection with the CloseStatusCode.AWAY.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Extensions Property

> Gets the extensions selected by the server.

> ## Syntax

> public string Extensions { get; }

> #### Value

> > A string that contains the extensions if any. By default, `String.Empty`. (Currently this will only ever be the `String.Empty`.)

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### IsAlive Property

> Gets a value indicating whether a connection is alive.

> ## Syntax

> public bool IsAlive { get; }

> #### Value

> > `true` if the connection is alive; otherwise, `false`.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### IsSecure Property

> Gets a value indicating whether a connection is secure.

> ## Syntax

> public bool IsSecure { get; }

> #### Value

> > `true` if the connection is secure; otherwise, `false`.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### OnClose Event

> Occurs when the WebSocketSharp.WebSocket receives a Close frame or the Close method is called.

> ## Syntax

> public event EventHandler<CloseEventArgs> OnClose

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### OnError Event

> Occurs when the WebSocketSharp.WebSocket gets an error.

> ## Syntax

> public event EventHandler<ErrorEventArgs> OnError

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### OnMessage Event

> Occurs when the WebSocketSharp.WebSocket receives a data frame.

> ## Syntax

> public event EventHandler<MessageEventArgs> OnMessage

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### OnOpen Event

> Occurs when the WebSocket connection has been established.

> ## Syntax

> public event EventHandler OnOpen

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Ping Method

> Pings using the WebSocket connection.

> ## Syntax

> public bool Ping ()

> #### Returns

> > `true` if the WebSocketSharp.WebSocket receives a Pong in a time; otherwise, `false`.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Ping Method

> Pings with the specified message using the WebSocket connection.

> ## Syntax

> public bool Ping (string message)

> #### Parameters

> > message
> >   A string that contains a message.

> #### Returns

> > `true` if the WebSocketSharp.WebSocket receives a Pong in a time; otherwise, `false`.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Protocol Property

> Gets the subprotocol selected by the server.

> ## Syntax

> public string Protocol { get; }

> #### Value

> > A string that contains the subprotocol if any. By default, `String.Empty`.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### ReadyState Property

> Gets the state of the connection.

> ## Syntax

> public WsState ReadyState { get; }

> #### Value

> > One of the WebSocketSharp.WsState. By default, `WsState.CONNECTING`.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Send Method

> Sends a binary data using the WebSocket connection.

> ## Syntax

> public void Send (byte[] data)

> #### Parameters

> > data
> >   An array of byte that contains a binary data to send.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Send Method

> Sends a binary data using the WebSocket connection.

> ## Syntax

> public void Send (System.IO.FileInfo file)

> #### Parameters

> > file
> >   A System.IO.FileInfo that contains a binary data to send.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Send Method

> Sends a text data using the WebSocket connection.

> ## Syntax

> public void Send (string data)

> #### Parameters

> > data
> >   A string that contains a text data to send.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### SendAsync Method

> Sends a binary data asynchronously using the WebSocket connection.

> ## Syntax

> public void SendAsync (byte[] data, Action completed)

> #### Parameters

> > data
> >   An array of byte that contains a binary data to send.
> > completed
> >   An Action delegate that references the method(s) called when the asynchronous operation completes.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### SendAsync Method

> Sends a binary data asynchronously using the WebSocket connection.

> ## Syntax

> public void SendAsync (System.IO.FileInfo file, Action completed)

> #### Parameters

> > file
> >   A System.IO.FileInfo that contains a binary data to send.
> > completed
> >   An Action delegate that references the method(s) called when the asynchronous operation completes.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### SendAsync Method

> Sends a text data asynchronously using the WebSocket connection.

> ## Syntax

> public void SendAsync (string data, Action completed)

> #### Parameters

> > data
> >   A string that contains a text data to send.
> > completed
> >   An Action delegate that references the method(s) called when the asynchronous operation completes.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)

### Url Property

> Gets the WebSocket URL.

> ## Syntax

> public Uri Url { get; }

> #### Value

> > A Uri that contains the WebSocket URL.

> ## Remarks

> Documentation for this section has not yet been entered.

> ## Requirements

> Namespace: WebSocketSharp
> Assembly: websocket-sharp (in websocket-sharp.dll)