Problem with WebSockets Draft

I have a troll with support for Web Sockets and Microsoft Draft. I use the API provided by them for the server, as well as the Silverlight fix for browsers that do not support web sockets. The information I'm working with comes from http://channel9.msdn.com/Events/MIX/MIX11/HTM10 and http://html5labs.interoperabilitybridges.com/prototypes/websockets/websockets/info My code compiles in the order he begins to open the connection and then fails. Here is my server side server code (in C # console application)

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.ServiceModel.WebSockets; namespace ChatBackend { class Program { static void Main(string[] args) { var host = new WebSocketsHost<MessageHandler>(); host.AddWebSocketsEndpoint("ws://localhost:4502/MessageHandler"); host.Open(); Console.ReadLine(); } } } 

Here's the MessageHandler class:

  class MessageHandler : WebSocketsService { public override void OnMessage(string value) { string returnMessage = "You just said '" + value + "'"; Console.WriteLine(value); SendMessage(returnMessage); } } 

This backend part seems to be working fine. Here's the end of the client:

  $(document).ready(function () { setTimeout(connect, 2050); }); function connect() { websocket = new WebSocketDraft("ws://localhost:4502/MessageHandler"); websocket.onopen = function() { websocket.send("test"); }; websocket.onclose = function () { alert("DIED"); }; websocket.onmessage = function(event) { sendMessage(new message(0, event.data, 0)); }; } 

EDIT: I checked my firewall and allowed to use the port that I used. Now the connection just hangs - it does not close, it does not open. Any ideas?

EDIT 2: I did some more research, it turned out that I needed to remove clientaccesspolicy.xml. It also turns out that I never had it, but I returned to custom 302 forwarding instead of 404, which was not found. This is fixed, but no progress. He is just hanging.

EDIT 3: Tried to disable Antivirus and firewall, no change Thanks - let me know if I need more code or information here.

+4
source share
3 answers

It finally worked! Turns out I had to add clientaccesspolicy.xml to the root folder of the default website on my server. I thought I should delete it - I read some information incorrectly and immediately forgot about it. The moral of the story: read the readme!

0
source

Can you use Firebug or something else and set a breakpoint on this line in jquery.slws.js (assuming it's used!)

 this.slws = slCtl.Content.services.createObject("websocket"); 

And then go and see where it doesnโ€™t work?

+1
source

Your URL definitely looks like it matches the setting on your server side. It is very difficult to find any examples of using WebSockets, since it is still such a new technology, but from what I could follow the only working example that I could find (it was on the html5labs website), I think maybe you trying to write to the outlet before it ends. In the above example, it looked like they were checking the readyState property of the socket and only trying to send if readyState === 1. The socket in this example opens by binding to the $(document).ready event and sending it is called from a button click.

0
source

All Articles