[Modify] Polish it
This commit is contained in:
parent
2bc95c251f
commit
02af0789e1
@ -14,8 +14,8 @@ namespace Example3
|
|||||||
{
|
{
|
||||||
// Create a new instance of the HttpServer class.
|
// Create a new instance of the HttpServer class.
|
||||||
//
|
//
|
||||||
// If you would like to provide the secure connection, you should create the instance with
|
// If you would like to provide the secure connection, you should create a new instance with
|
||||||
// the 'secure' parameter set to true, or the https scheme HTTP URL.
|
// the 'secure' parameter set to true, or an https scheme HTTP URL.
|
||||||
|
|
||||||
var httpsv = new HttpServer (4649);
|
var httpsv = new HttpServer (4649);
|
||||||
//var httpsv = new HttpServer (5963, true);
|
//var httpsv = new HttpServer (5963, true);
|
||||||
@ -51,7 +51,13 @@ namespace Example3
|
|||||||
httpsv.Log.Level = LogLevel.Trace;
|
httpsv.Log.Level = LogLevel.Trace;
|
||||||
|
|
||||||
// To change the wait time for the response to the WebSocket Ping or Close.
|
// To change the wait time for the response to the WebSocket Ping or Close.
|
||||||
httpsv.WaitTime = TimeSpan.FromSeconds (2);
|
//httpsv.WaitTime = TimeSpan.FromSeconds (2);
|
||||||
|
|
||||||
|
// Not to remove the inactive WebSocket sessions periodically.
|
||||||
|
//httpsv.KeepClean = false;
|
||||||
|
|
||||||
|
// To resolve to wait for socket in TIME_WAIT state.
|
||||||
|
//httpsv.ReuseAddress = true;
|
||||||
#endif
|
#endif
|
||||||
/* To provide the secure connection.
|
/* To provide the secure connection.
|
||||||
var cert = ConfigurationManager.AppSettings["ServerCertFile"];
|
var cert = ConfigurationManager.AppSettings["ServerCertFile"];
|
||||||
@ -102,12 +108,6 @@ namespace Example3
|
|||||||
res.WriteContent (content);
|
res.WriteContent (content);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Not to remove the inactive WebSocket sessions periodically.
|
|
||||||
//httpsv.KeepClean = false;
|
|
||||||
|
|
||||||
// To resolve to wait for socket in TIME_WAIT state.
|
|
||||||
//httpsv.ReuseAddress = true;
|
|
||||||
|
|
||||||
// Add the WebSocket services.
|
// Add the WebSocket services.
|
||||||
httpsv.AddWebSocketService<Echo> ("/Echo");
|
httpsv.AddWebSocketService<Echo> ("/Echo");
|
||||||
httpsv.AddWebSocketService<Chat> ("/Chat");
|
httpsv.AddWebSocketService<Chat> ("/Chat");
|
||||||
@ -115,7 +115,8 @@ namespace Example3
|
|||||||
/* Add the WebSocket service with initializing.
|
/* Add the WebSocket service with initializing.
|
||||||
httpsv.AddWebSocketService<Chat> (
|
httpsv.AddWebSocketService<Chat> (
|
||||||
"/Chat",
|
"/Chat",
|
||||||
() => new Chat ("Anon#") {
|
() =>
|
||||||
|
new Chat ("Anon#") {
|
||||||
// To send the Sec-WebSocket-Protocol header that has a subprotocol name.
|
// To send the Sec-WebSocket-Protocol header that has a subprotocol name.
|
||||||
Protocol = "chat",
|
Protocol = "chat",
|
||||||
// To emit a WebSocket.OnMessage event when receives a ping.
|
// To emit a WebSocket.OnMessage event when receives a ping.
|
||||||
@ -126,14 +127,14 @@ namespace Example3
|
|||||||
OriginValidator = val => {
|
OriginValidator = val => {
|
||||||
// Check the value of the Origin header, and return true if valid.
|
// Check the value of the Origin header, and return true if valid.
|
||||||
Uri origin;
|
Uri origin;
|
||||||
return !val.IsNullOrEmpty () &&
|
return !val.IsNullOrEmpty ()
|
||||||
Uri.TryCreate (val, UriKind.Absolute, out origin) &&
|
&& Uri.TryCreate (val, UriKind.Absolute, out origin)
|
||||||
origin.Host == "localhost";
|
&& origin.Host == "localhost";
|
||||||
},
|
},
|
||||||
// To validate the Cookies.
|
// To validate the cookies.
|
||||||
CookiesValidator = (req, res) => {
|
CookiesValidator = (req, res) => {
|
||||||
// Check the Cookies in 'req', and set the Cookies to send to the client with 'res'
|
// Check the cookies in 'req', and set the cookies to send to
|
||||||
// if necessary.
|
// the client with 'res' if necessary.
|
||||||
foreach (Cookie cookie in req) {
|
foreach (Cookie cookie in req) {
|
||||||
cookie.Expired = true;
|
cookie.Expired = true;
|
||||||
res.Add (cookie);
|
res.Add (cookie);
|
||||||
@ -141,7 +142,8 @@ namespace Example3
|
|||||||
|
|
||||||
return true; // If valid.
|
return true; // If valid.
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
httpsv.Start ();
|
httpsv.Start ();
|
||||||
|
Loading…
Reference in New Issue
Block a user