You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
vtortola edited this page Jun 17, 2014
·
2 revisions
WebSocketListener can be used in many ways. If you are more familiar with event driven approaches, you can create a very simple WebSocketEventListener class that allows you to subscribe to events, rather than doing asynchronous awaits. For example, a echo service would look like this:
using(varserver=newWebSocketEventListener(newIPEndPoint(IPAddress.Any,8009))){server.OnConnect+=(ws)=>Console.WriteLine("Connection from "+ws.RemoteEndpoint);server.OnDisconnect+=(ws)=>Console.WriteLine("Disconnection from "+ws.RemoteEndpoint);server.OnError+=(ws,ex)=>Console.WriteLine("Error: "+ex.Message);server.OnMessage+=(ws,msg)=>{Console.WriteLine("Message from ["+ws.RemoteEndpoint+"]: "+msg);ws.WriteStringAsync(msg,CancellationToken.None).Wait();};server.Start();
...}
The WebSocketEventListener class can be found here.