Skip to content

Instantly share code, notes, and snippets.

@devdays
Created November 30, 2014 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdays/ea7e19f0a6732b1cf46b to your computer and use it in GitHub Desktop.
Save devdays/ea7e19f0a6732b1cf46b to your computer and use it in GitHub Desktop.
Broadcast using WebSocket
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