Search code examples
angularjsfirefoxxsockets.net

XSockets do not connect from Firefox


I need to use web sockets for some interactions with the user. I have pretty much copypasted solution from here - http://xsockets.net/blog/angular-js-xsocketsnet and got an issue with Firefox (27.0.1).

When I try to make this call (TwoWayBinding is my XSockets controller, I'm using .NET MVC on host side):

var connect = function (url) {
    var deferred = $q.defer();
    socket = new XSockets.WebSocket(url);
    socket.on(XSockets.Events.open, function (conn) {
        $rootScope.$apply(function () {
            deferred.resolve(conn);
        });
    });
    return deferred.promise;
};

connect("ws://localhost:49200/TwoWayBinding").then(function (ctx) {
    isConnected = true;
    queued.forEach(function (msg, i) {
        publish(msg.t, msg.d);
    });
queued = [];
});

I always get an error from Firebug:

Firefox can't establish a connection to the server at ws://localhost:49200/TwoWayBinding.
this.webSocket = new window.WebSocket(url, subprotocol || "XSocketsNET");

The same code works well in Chrome, it gets connected and I'm getting messages sent from host. Mentioned methods are wrapped into angular service, but this all works, I do not think this should be a problem.

One thing I was able to figure out from Fiddler was this:

Chrome:

Result Protocol Host URL Body Caching Content-Type Process Comments Custom
3 200 HTTP Tunnel to localhost:49200 0 chrome:3976

Result Protocol Host URL Body Caching Content-Type Process Comments Custom
6 101 HTTP localhost:49200 /TwoWayBinding?XSocketsClientStorageGuid=5cf5c99aafd141d1b247ed70107659e0 0 chrome:3976

Firefox:

Result Protocol Host URL Body Caching Content-Type Process Comments Custom
1740 200 HTTP Tunnel to localhost:49200 0 firefox:1420

Result Protocol Host URL Body Caching Content-Type Process Comments Custom
1741 - HTTP localhost:49200 /TwoWayBinding -1 firefox:1420

Simply said - there is some additional parameter XSocketsClientStorageGuid in the response for Chrome which does not occur in the respose to FF. I'm not sure if that has any impact or if I'm completely wrong but will appreciate any advice if somebody experiences same issue.

Update: It looks like the critical line is this one

socket = new XSockets.WebSocket(url);

as the socket is not created properly in Firefox. But I still not have the cause of this.


Solution

  • What version are you running on , did you make a new installation of XSockets.NET using the Nuget Package or did you use the git example mentioned in the quesion above?

    I just did a test on FF 26.0 and 27.0.1 , and it did go well using this pice of example;

    http://xsockets.github.io/XSockets.JavaScript.API/test/index.html

    I will have a look at the old Angular example asap and makre sure it is fixed of there is a problem!

    Kind regards

    Magnus