`e` has come across as `EventArgs.Empty`, so there is no operation on`e`.
`e` has come across as `EventArgs.Empty`, so you don't use`e`.
##### WebSocket.OnMessage event #####
##### WebSocket.OnMessage event #####
@ -84,7 +84,11 @@ ws.OnMessage += (sender, e) =>
};
};
```
```
`e.Type` (`WebSocketSharp.MessageEventArgs.Type`, the type of this property is `WebSocketSharp.Opcode`) indicates the **Frame type** of a WebSocket frame, so by checking this property, you determine which item you should operate.
`e.Type` (`WebSocketSharp.MessageEventArgs.Type`, the type of this property is `WebSocketSharp.Opcode`) indicates the **Frame Type** of a WebSocket frame, so by checking this property, you determine which item you should use.
If `e.Type` equals `Opcode.TEXT`, you use `e.Data` (`WebSocketSharp.MessageEventArgs.Data`, the type of this property is `string`) that contains the received data.
If `e.Type` equals `Opcode.BINARY`, you use `e.RawData` (`WebSocketSharp.MessageEventArgs.RawData`, the type of this property is `byte[]`) that contains the received data.
```cs
```cs
if (e.Type == Opcode.TEXT)
if (e.Type == Opcode.TEXT)
@ -100,10 +104,6 @@ if (e.Type == Opcode.BINARY)
}
}
```
```
If `e.Type` equaled `Opcode.TEXT`, you would operate `e.Data` (`WebSocketSharp.MessageEventArgs.Data`, the type of this property is `string`).
If `e.Type` equaled `Opcode.BINARY`, you would operate `e.RawData` (`WebSocketSharp.MessageEventArgs.RawData`, the type of this property is `byte[]`).
##### WebSocket.OnError event #####
##### WebSocket.OnError event #####
A `WebSocket.OnError` event occurs when the `WebSocket` gets an error.
A `WebSocket.OnError` event occurs when the `WebSocket` gets an error.
@ -114,7 +114,7 @@ ws.OnError += (sender, e) =>
...
...
};
};
```
```
`e.Message` (`WebSocketSharp.ErrorEventArgs.Message`, the type of this property is `string`) contains an error message, so you operate this.
`e.Message` (`WebSocketSharp.ErrorEventArgs.Message`, the type of this property is `string`) contains an error message, so you use this.
##### WebSocket.OnClose event #####
##### WebSocket.OnClose event #####
@ -127,7 +127,7 @@ ws.OnClose += (sender, e) =>
};
};
```
```
`e.Code` (`WebSocketSharp.CloseEventArgs.Code`, the type of this property is `ushort`) contains a status code indicating the reason for closure and `e.Reason` (`WebSocketSharp.CloseEventArgs.Reason`, the type of this property is `string`) contains the reason for closure, so you operate these.
`e.Code` (`WebSocketSharp.CloseEventArgs.Code`, the type of this property is `ushort`) contains a status code indicating the reason for closure and `e.Reason` (`WebSocketSharp.CloseEventArgs.Reason`, the type of this property is `string`) contains the reason for closure, so you use these.
#### Step 4 ####
#### Step 4 ####
@ -157,7 +157,7 @@ Closing the WebSocket connection.
ws.Close(code, reason);
ws.Close(code, reason);
```
```
If you wanted to close the WebSocket connection explicitly, you would use the `Close` method.
If you want to close the WebSocket connection explicitly, you can use the `Close` method.
And the `Close` method is overloaded. The types of `code` are `WebSocketSharp.CloseStatusCode` and `ushort`, the type of `reason` is `string`.
And the `Close` method is overloaded. The types of `code` are `WebSocketSharp.CloseStatusCode` and `ushort`, the type of `reason` is `string`.
@ -266,7 +266,7 @@ You can add any WebSocket service with a specified path to the service to your `
The type of `T` inherits `WebSocketService` class, so you can use a class that was created in **Step 2**.
The type of `T` inherits `WebSocketService` class, so you can use a class that was created in **Step 2**.
If you created a instance of the `WebSocketServer` class without the port number, the `WebSocketServer`would set the port number to **80** automatically. So it is necessary to run with root permission.
If you create a instance of the `WebSocketServer` class without the port number, the `WebSocketServer` set the port number to **80** automatically. So it is necessary to run with root permission.
$ sudo mono example2.exe
$ sudo mono example2.exe
@ -285,7 +285,7 @@ wssv.OnError += (sender, e) =>
};
};
```
```
`e.Message` (`WebSocketSharp.ErrorEventArgs.Message`, the type of this property is `string`) contains an error message, so you operate this.
`e.Message` (`WebSocketSharp.ErrorEventArgs.Message`, the type of this property is `string`) contains an error message, so you use this.