Fix due to the added QueryString property in WebSocketService.cs

This commit is contained in:
sta
2012-10-22 14:58:43 +09:00
parent a7eef35c96
commit c55b5d6479
78 changed files with 1346 additions and 830 deletions
+30 -2
View File
@@ -6,9 +6,37 @@ namespace Example2
{
public class Chat : WebSocketService
{
protected override void onMessage(object sender, MessageEventArgs e)
private static object _forId = new object();
private static uint _id = 0;
private string _name;
private string getName()
{
Publish(e.Data);
lock (_forId)
{
return QueryString.Exists("name")
? QueryString["name"]
: "anon#" + (++_id);
}
}
protected override void OnOpen(object sender, EventArgs e)
{
_name = getName();
}
protected override void OnMessage(object sender, MessageEventArgs e)
{
var msg = String.Format("{0}: {1}", _name, e.Data);
Publish(msg);
}
protected override void OnClose(object sender, CloseEventArgs e)
{
var msg = String.Format("{0} got logged off...", _name);
Publish(msg);
}
}
}
+7 -9
View File
@@ -2,18 +2,16 @@ using System;
using WebSocketSharp;
using WebSocketSharp.Server;
namespace Example2
{
namespace Example2 {
public class Echo : WebSocketService
{
protected override void onMessage(object sender, MessageEventArgs e)
protected override void OnMessage(object sender, MessageEventArgs e)
{
Send(e.Data);
}
protected override void onClose(object sender, CloseEventArgs e)
{
Console.WriteLine("[Echo] Close({0})", e.Code);
var msg = QueryString.Exists("name")
? String.Format("'{0}' returns to {1}", e.Data, QueryString["name"])
: e.Data;
Send(msg);
}
}
}
Binary file not shown.
+11 -1
View File
@@ -8,10 +8,18 @@ namespace Example2
public static void Main(string[] args)
{
/* Single service server
var wssv = new WebSocketServer<Echo>("ws://localhost:4649");
//var wssv = new WebSocketServer<Echo>("ws://localhost:4649");
var wssv = new WebSocketServer<Echo>("ws://localhost:4649/Echo");
//var wssv = new WebSocketServer<Echo>("ws://localhost:4649/エコー");
//var wssv = new WebSocketServer<Echo>(4649);
//var wssv = new WebSocketServer<Echo>(4649, "/Echo");
//var wssv = new WebSocketServer<Echo>(4649, "/エコー");
//var wssv = new WebSocketServer<Chat>("ws://localhost:4649");
//var wssv = new WebSocketServer<Chat>("ws://localhost:4649/Chat");
//var wssv = new WebSocketServer<Chat>("ws://localhost:4649/チャット");
//var wssv = new WebSocketServer<Chat>(4649);
//var wssv = new WebSocketServer<Chat>(4649, "/Chat");
//var wssv = new WebSocketServer<Chat>(4649, "/チャット");
wssv.Start();
Console.WriteLine(
@@ -22,7 +30,9 @@ namespace Example2
// Multi services server
var wssv = new WebSocketServer(4649);
wssv.AddService<Echo>("/Echo");
wssv.AddService<Echo>("/エコー");
wssv.AddService<Chat>("/Chat");
wssv.AddService<Chat>("/チャット");
wssv.Start();
Console.WriteLine(
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.