Added a new AddWebSocketService method to the WebSocketServer and HttpServer classes

This commit is contained in:
sta
2013-10-02 14:39:56 +09:00
parent 2b57a58da2
commit 24e74b60b7
8 changed files with 356 additions and 64 deletions

View File

@@ -10,10 +10,21 @@ namespace Example3
private static int _num = 0;
private string _name;
private string _prefix;
public Chat ()
: this ("anon#")
{
}
public Chat (string prefix)
{
_prefix = prefix;
}
private string getName ()
{
return Context.QueryString ["name"] ?? ("anon#" + getNum ());
return Context.QueryString ["name"] ?? (_prefix + getNum ());
}
private int getNum ()

View File

@@ -25,6 +25,7 @@ namespace Example3
//_httpsv.KeepClean = false;
_httpsv.AddWebSocketService<Echo> ("/Echo");
_httpsv.AddWebSocketService<Chat> ("/Chat");
//_httpsv.AddWebSocketService<Chat> ("/Chat", () => new Chat ("Anon#"));
_httpsv.OnGet += (sender, e) =>
{
@@ -34,7 +35,7 @@ namespace Example3
_httpsv.Start ();
if (_httpsv.IsListening)
{
Console.WriteLine ("HTTP Server listening on port: {0} service path:", _httpsv.Port);
Console.WriteLine ("An HTTP Server listening on port: {0} service path:", _httpsv.Port);
foreach (var path in _httpsv.WebSocketServices.ServicePaths)
Console.WriteLine (" {0}", path);