[Modify] Polish it

This commit is contained in:
sta 2016-07-24 17:04:25 +09:00
parent 40b23a6aea
commit 6786cb017b

View File

@ -15,18 +15,20 @@ namespace Example
// use the using statement. And the WebSocket connection will be closed with // use the using statement. And the WebSocket connection will be closed with
// close status 1001 (going away) when the control leaves the using block. // 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, // If you would like to connect to a server with the secure connection,
// you should create the instance with the wss scheme WebSocket URL. // you should create a new instance with a wss scheme WebSocket URL.
using (var nf = new Notifier ()) using (var nf = new Notifier ())
using (var ws = new WebSocket ("ws://echo.websocket.org")) using (var ws = new WebSocket ("ws://echo.websocket.org"))
//using (var ws = new WebSocket ("wss://echo.websocket.org")) //using (var ws = new WebSocket ("wss://echo.websocket.org"))
//using (var ws = new WebSocket ("ws://localhost:4649/Echo")) //using (var ws = new WebSocket ("ws://localhost:4649/Echo"))
//using (var ws = new WebSocket ("wss://localhost:5963/Echo"))
//using (var ws = new WebSocket ("ws://localhost:4649/Echo?name=nobita")) //using (var ws = new WebSocket ("ws://localhost:4649/Echo?name=nobita"))
//using (var ws = new WebSocket ("wss://localhost:4649/Echo")) //using (var ws = new WebSocket ("wss://localhost:5963/Echo?name=nobita"))
//using (var ws = new WebSocket ("ws://localhost:4649/Chat")) //using (var ws = new WebSocket ("ws://localhost:4649/Chat"))
//using (var ws = new WebSocket ("wss://localhost:5963/Chat"))
//using (var ws = new WebSocket ("ws://localhost:4649/Chat?name=nobita")) //using (var ws = new WebSocket ("ws://localhost:4649/Chat?name=nobita"))
//using (var ws = new WebSocket ("wss://localhost:4649/Chat")) //using (var ws = new WebSocket ("wss://localhost:5963/Chat?name=nobita"))
{ {
// Set the WebSocket events. // Set the WebSocket events.
@ -38,7 +40,8 @@ namespace Example
Summary = "WebSocket Message", Summary = "WebSocket Message",
Body = !e.IsPing ? e.Data : "Received a ping.", Body = !e.IsPing ? e.Data : "Received a ping.",
Icon = "notification-message-im" Icon = "notification-message-im"
}); }
);
ws.OnError += (sender, e) => ws.OnError += (sender, e) =>
nf.Notify ( nf.Notify (
@ -46,7 +49,8 @@ namespace Example
Summary = "WebSocket Error", Summary = "WebSocket Error",
Body = e.Message, Body = e.Message,
Icon = "notification-message-im" Icon = "notification-message-im"
}); }
);
ws.OnClose += (sender, e) => ws.OnClose += (sender, e) =>
nf.Notify ( nf.Notify (
@ -54,17 +58,20 @@ namespace Example
Summary = String.Format ("WebSocket Close ({0})", e.Code), Summary = String.Format ("WebSocket Close ({0})", e.Code),
Body = e.Reason, Body = e.Reason,
Icon = "notification-message-im" Icon = "notification-message-im"
}); }
);
#if DEBUG #if DEBUG
// To change the logging level. // To change the logging level.
ws.Log.Level = LogLevel.Trace; ws.Log.Level = LogLevel.Trace;
// To change the wait time for the response to the Ping or Close. // To change the wait time for the response to the Ping or Close.
ws.WaitTime = TimeSpan.FromSeconds (10); //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; //ws.EmitOnPing = true;
// To enable the redirection.
//ws.EnableRedirection = true;
#endif #endif
// To enable the Per-message Compression extension. // To enable the Per-message Compression extension.
//ws.Compression = CompressionMethod.Deflate; //ws.Compression = CompressionMethod.Deflate;
@ -76,7 +83,9 @@ namespace Example
String.Format ( String.Format (
"Certificate:\n- Issuer: {0}\n- Subject: {1}", "Certificate:\n- Issuer: {0}\n- Subject: {1}",
certificate.Issuer, certificate.Issuer,
certificate.Subject)); certificate.Subject
)
);
return true; // If the server certificate is valid. return true; // If the server certificate is valid.
}; };
@ -88,16 +97,13 @@ namespace Example
// To send the Origin header. // To send the Origin header.
//ws.Origin = "http://localhost:4649"; //ws.Origin = "http://localhost:4649";
// To send the Cookies. // To send the cookies.
//ws.SetCookie (new Cookie ("name", "nobita")); //ws.SetCookie (new Cookie ("name", "nobita"));
//ws.SetCookie (new Cookie ("roles", "\"idiot, gunfighter\"")); //ws.SetCookie (new Cookie ("roles", "\"idiot, gunfighter\""));
// To connect through the HTTP Proxy server. // To connect through the HTTP Proxy server.
//ws.SetProxy ("http://localhost:3128", "nobita", "password"); //ws.SetProxy ("http://localhost:3128", "nobita", "password");
// To enable the redirection.
//ws.EnableRedirection = true;
// Connect to the server. // Connect to the server.
ws.Connect (); ws.Connect ();