From b8bc01d100e93895c3f2e92471f264ab517fcb4c Mon Sep 17 00:00:00 2001 From: sta Date: Sun, 15 Nov 2015 15:36:01 +0900 Subject: [PATCH] [Modify] Polish it --- Example/Notifier.cs | 4 +--- Example/Program.cs | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Example/Notifier.cs b/Example/Notifier.cs index 7f3c524f..f21eec32 100644 --- a/Example/Notifier.cs +++ b/Example/Notifier.cs @@ -54,9 +54,7 @@ namespace Example private NotificationMessage dequeue () { lock (_sync) - return _queue.Count > 0 - ? _queue.Dequeue () - : null; + return _queue.Count > 0 ? _queue.Dequeue () : null; } public void Close () diff --git a/Example/Program.cs b/Example/Program.cs index 4ea070d1..f3d91f6d 100644 --- a/Example/Program.cs +++ b/Example/Program.cs @@ -9,15 +9,15 @@ namespace Example { public static void Main (string[] args) { - /* Create a new instance of the WebSocket class. - * - * The WebSocket class inherits the System.IDisposable interface, so you can use the using - * statement. And the WebSocket connection will be closed with close status 1001 (going away) - * when the control leaves the using block. - * - * If you would like to connect to the server with the secure connection, you should create - * the instance with the wss scheme WebSocket URL. - */ + // Create a new instance of the WebSocket class. + // + // The WebSocket class inherits the System.IDisposable interface, so you can + // use the using statement. And the WebSocket connection will be closed with + // close status 1001 (going away) when the control leaves the using block. + // + // If you would like to connect to the server with the secure connection, + // you should create the instance with the wss scheme WebSocket URL. + using (var nf = new Notifier ()) using (var ws = new WebSocket ("ws://echo.websocket.org")) //using (var ws = new WebSocket ("wss://echo.websocket.org")) @@ -28,14 +28,15 @@ namespace Example //using (var ws = new WebSocket ("ws://localhost:4649/Chat?name=nobita")) //using (var ws = new WebSocket ("wss://localhost:4649/Chat")) { - // To set the WebSocket events. + // Set the WebSocket events. + ws.OnOpen += (sender, e) => ws.Send ("Hi, there!"); ws.OnMessage += (sender, e) => nf.Notify ( new NotificationMessage { Summary = "WebSocket Message", - Body = e.Type != Opcode.Ping ? e.Data : "Received a Ping.", + Body = !e.IsPing ? e.Data : "Received a ping.", Icon = "notification-message-im" }); @@ -62,7 +63,7 @@ namespace Example // To change the wait time for the response to the Ping or Close. ws.WaitTime = TimeSpan.FromSeconds (10); - // To emit a WebSocket.OnMessage event when receives a Ping. + // To emit a WebSocket.OnMessage event when receives a ping. ws.EmitOnPing = true; #endif // To enable the Per-message Compression extension. @@ -81,7 +82,7 @@ namespace Example }; */ - // To set the credentials for the HTTP Authentication (Basic/Digest). + // To send the credentials for the HTTP Authentication (Basic/Digest). //ws.SetCredentials ("nobita", "password", false); // To send the Origin header.