Fixed a few typo

This commit is contained in:
sta 2012-08-08 11:32:19 +09:00
parent 34f33d8e31
commit 2f402b4ce0

View File

@ -10,8 +10,10 @@
Required namespaces. Required namespaces.
```cs
using WebSocketSharp; using WebSocketSharp;
using WebSocketSharp.Frame; using WebSocketSharp.Frame;
```
`WebSocket` class exists in `WebSocketSharp` namespace, WebSocket data frame resources (e.g. `WsFrame` class) exist in `WebSocketSharp.Frame` namespace. `WebSocket` class exists in `WebSocketSharp` namespace, WebSocket data frame resources (e.g. `WsFrame` class) exist in `WebSocketSharp.Frame` namespace.
@ -19,10 +21,12 @@ Required namespaces.
Creating a instance of `WebSocket` class. Creating a instance of `WebSocket` class.
```cs
using (WebSocket ws = new WebSocket("ws://example.com")) using (WebSocket ws = new WebSocket("ws://example.com"))
{ {
... ...
} }
```
`WebSocket` class inherits `IDisposable` interface, so you can use `using` statement. `WebSocket` class inherits `IDisposable` interface, so you can use `using` statement.
@ -34,10 +38,12 @@ Setting `WebSocket` event handlers.
`WebSocket.OnOpen` event is emitted immediately after WebSocket connection has been established. `WebSocket.OnOpen` event is emitted immediately after WebSocket connection has been established.
```cs
ws.OnOpen += (sender, e) => ws.OnOpen += (sender, e) =>
{ {
... ...
}; };
```
`e` has come across as `EventArgs.Empty`, so there is no operation on `e`. `e` has come across as `EventArgs.Empty`, so there is no operation on `e`.
@ -45,13 +51,16 @@ Setting `WebSocket` event handlers.
`WebSocket.OnMessage` event is emitted each time WebSocket data frame is received. `WebSocket.OnMessage` event is emitted each time WebSocket data frame is received.
```cs
ws.OnMessage += (sender, e) => ws.OnMessage += (sender, e) =>
{ {
... ...
}; };
```
**Frame type** of received WebSocket data frame is stored in `e.Type` (`WebSocketSharp.MessageEventArgs.Type`, its type is `WebSocketSharp.Frame.Opcode`), so you check it out and you determine which item you should operate. **Frame type** of received WebSocket data frame is stored in `e.Type` (`WebSocketSharp.MessageEventArgs.Type`, its type is `WebSocketSharp.Frame.Opcode`), so you check it out and you determine which item you should operate.
```cs
switch (e.Type) switch (e.Type)
{ {
case Opcode.TEXT: case Opcode.TEXT:
@ -63,6 +72,7 @@ Setting `WebSocket` event handlers.
default: default:
break; break;
} }
```
If `e.Type` is `Opcode.TEXT`, you operate `e.Data` (`WebSocketSharp.MessageEventArgs.Data`, its type is `string`). If `e.Type` is `Opcode.TEXT`, you operate `e.Data` (`WebSocketSharp.MessageEventArgs.Data`, its type is `string`).
@ -72,21 +82,24 @@ If `e.Type` is `Opcode.BINARY`, you operate `e.RawData` (`WebSocketSharp.Message
`WebSocket.OnError` event is emitted when some error is occurred. `WebSocket.OnError` event is emitted when some error is occurred.
```cs
ws.OnError += (sender, e) => ws.OnError += (sender, e) =>
{ {
... ...
}; };
```
Error message is stored in `e.Message` (`WebSocketSharp.ErrorEventArgs.Message`, its type is `string`), so you operate it. Error message is stored in `e.Message` (`WebSocketSharp.ErrorEventArgs.Message`, its type is `string`), so you operate it.
##### WebSocket.OnClose event ##### ##### WebSocket.OnClose event #####
`WebSocket.OnClose` event is emitted when WebSocket connection is closed. `WebSocket.OnClose` event is emitted when WebSocket connection is closed.
```cs
ws.OnClose += (sender, e) => ws.OnClose += (sender, e) =>
{ {
... ...
}; };
```
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`), so you operate them. 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`), so you operate them.
@ -94,13 +107,17 @@ Close status code is stored in `e.Code` (`WebSocketSharp.CloseEventArgs.Code`, i
Connecting to server using WebSocket. Connecting to server using WebSocket.
```cs
ws.Connect(); ws.Connect();
```
#### Step 5 #### #### Step 5 ####
Sending data. Sending data.
```cs
ws.Send(data); ws.Send(data);
```
`WebSocket.Send` method is overloaded. `WebSocket.Send` method is overloaded.
@ -110,7 +127,9 @@ Sending data.
Closing WebSocket connection. Closing WebSocket connection.
```cs
ws.Close(code, reason); ws.Close(code, reason);
```
If you want to close WebSocket connection explicitly, you can use `Close` method. If you want to close WebSocket connection explicitly, you can use `Close` method.
@ -124,7 +143,9 @@ Type of `code` is `WebSocketSharp.Frame.CloseStatusCode`, type of `reason` is `s
Required namespace. Required namespace.
```cs
using WebSocketSharp.Server; using WebSocketSharp.Server;
```
`WebSocketServer<T>` class and `WebSocketService` class exist in `WebSocketSharp.Server` namespace. `WebSocketServer<T>` class and `WebSocketService` class exist in `WebSocketSharp.Server` namespace.
@ -168,7 +189,9 @@ For example, if you want to provide the chat service,
Creating a instance of `WebSocketServer<T>` class. Creating a instance of `WebSocketServer<T>` class.
```cs
var wssv = new WebSocketServer<Echo>("ws://example.com:4649"); var wssv = new WebSocketServer<Echo>("ws://example.com:4649");
```
Type of `T` inherits `WebSocketService` class, so you can use a class that was created in **Step 2**. Type of `T` inherits `WebSocketService` class, so you can use a class that was created in **Step 2**.
@ -185,10 +208,12 @@ Setting WebSocketServer event handler.
`WebSocketServer<T>.OnError` event is emitted when some error is occurred. `WebSocketServer<T>.OnError` event is emitted when some error is occurred.
```cs
wssv.OnError += (sender, e) => wssv.OnError += (sender, e) =>
{ {
... ...
}; };
```
Error message is stored in `e.Message` (`WebSocketSharp.ErrorEventArgs.Message`, its type is `string`), so you operate it. Error message is stored in `e.Message` (`WebSocketSharp.ErrorEventArgs.Message`, its type is `string`), so you operate it.
@ -196,13 +221,17 @@ Error message is stored in `e.Message` (`WebSocketSharp.ErrorEventArgs.Message`,
Starting server. Starting server.
```cs
wssv.Start(); wssv.Start();
```
#### Step 6 #### #### Step 6 ####
Stopping server. Stopping server.
```cs
wssv.Stop(); wssv.Stop();
```
## Examples ## ## Examples ##