In `WebSocketSharp` namespace `WebSocket` class exists, in `WebSocketSharp.Frame` namespace WebSocket data frame resources (e.g. `WsFrame` class) exist.
### Step 2 ###
Creating instance of `WebSocket` class.
using (WebSocket ws = new WebSocket("ws://example.com"))
{
...
}
So `WebSocket` class inherits `IDisposable` interface, you can use `using` statement.
`WebSocket.OnOpen` event is emitted immediately after WebSocket connection has been established.
ws.OnOpen += (sender, e) =>
{
...
};
So `e` has come across as `EventArgs.Empty`, there is no operation on `e`.
#### WebSocket.OnMessage event ####
`WebSocket.OnMessage` event is emitted each time WebSocket data frame is received.
ws.OnMessage += (sender, e) =>
{
...
};
So **type** of received WebSocket data frame is stored in `e.Type` (`WebSocketSharp.MessageEventArgs.Type`, its type is `WebSocketSharp.Frame.Opcode`), you check it out and you determine which item you should operate.
switch (e.Type)
{
case Opcode.TEXT:
...
break;
case Opcode.BINARY:
...
break;
default:
break;
}
If `e.Type` is `Opcode.TEXT`, you operate `e.Data` (`WebSocketSharp.MessageEventArgs.Data`, its type is `string`).
`WebSocket.OnClose` event is emitted when WebSocket connection is closed.
ws.OnClose += (sender, e) =>
{
...
};
So close status code is stored in `e.Code` (`WebSocketSharp.CloseEventArgs.Code`, its type is `WebSocketSharp.Frame.CloseStatusCode`) and reason of close is stored in `e.Reason` (`WebSocketSharp.CloseEventArgs.Reason`, its type is `string`), you operate them.