Created
November 30, 2014 19:39
-
-
Save devdays/ea7e19f0a6732b1cf46b to your computer and use it in GitHub Desktop.
Broadcast using WebSocket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestWebSocketHandler : WebSocketHandler | |
{ | |
private static WebSocketCollection clients = new WebSocketCollection(); | |
private string name; | |
public override void OnOpen() | |
{ | |
this.name = this.WebSocketContext.QueryString["name"]; | |
clients.Add(this); | |
clients.Broadcast(name + " has connected."); | |
} | |
public override void OnMessage(string message) | |
{ | |
clients.Broadcast(string.Format("{0} said: {1}", name, message)); | |
} | |
public override void OnClose() | |
{ | |
clients.Remove(this); | |
clients.Broadcast(string.Format("{0} has gone away.", name)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment