I'm new in web sockets and trying to create one using asp.net Generic Handler and JavaScript WebSocket Class
JavaScript
<script type="text/javascript"> window.onload= function () { var name = prompt('what is your name?:'); var url = 'ws://localhost:5707/ws.ashx?name=' + name; var ws = new WebSocket(url); ws.onopen = function () { alert('Connection Opened'); }; ws.onmessage = function (e) { }; ws.onclose = function () { alert('Connection Close'); }; ws.onerror = function (e) { alert('Error') }; } </script> C# Generic Handler Called ws.ashx
public class ws : IHttpHandler { public void ProcessRequest(HttpContext context) { if (context.IsWebSocketRequest) context.AcceptWebSocketRequest(new TestWebSocketHandler()); } public bool IsReusable { get { return false; } } } Class TestWebSocketHandler which is inherits from WebSocketHandler
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)); } } My Problem is
when the websocket intend to open i noticed that when went to the handler the
context.IsWebSocketRequest // returns false and then it fires Error on the client says
Firefox can't establish a connection to the server at ws://localhost:5707/ws.ashx?name=j
and then close the connection instantiation
i need to know where is the problem ? kindly
i'm using vs 2013 under windows 7 and i think its IIS 6 which i work on