Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ws://null #73

Open
noamtcohen opened this Issue · 10 comments

8 participants

@noamtcohen

Hi,

I am running the same application in the same browsers on two different machines,
on one machine every thing works great but on the other I get this error:

WebSocket connection to 'ws://null/' 
failed: Unexpected response code: 200 binary.js 25

Browser: node-webkit
First machine: Windows 7 64
Second machine: Windows XP 2002 SP2
Please help, Thanks.

@benfoxall

This error comes from the supportsBinaryWebsockets feature test

The problem is that some ISPs will redirect you to a help page if the dns doesn't resolve, this can mean that ws://null gets caught and returns a 200. If this is the issue - you should get a response from running ping null.

I'm not sure if this will be a problem for the feature test.

One way around this is to use a different DNS server - the Google public DNS (8.8.8.8) might be a good choice.

@DongDiddler

I'm getting this same issue, I am using Google public DNS.

Firefox can't establish a connection to the server at ws://null/. binary.js:22
@GregTurner

Chrome 36 puts up its "grey shield" warning when using a secure wss connection. A quick change to wss://null in the source solves this problem. That being said, I'm not sure it's still a legit browser test for web sockets.

@benfoxall

Would that cause issues for using this on a non-secure page?

modernizr will switch based on the current protocol - maybe it would be better to follow that.

var protocol = 'https:'==location.protocol?'wss':'ws',
protoBin;

if('WebSocket' in window) {
  if( protoBin = 'binaryType' in WebSocket.prototype ) {
    return protoBin;
  }
  try {
    return !!(new WebSocket(protocol+'://.').binaryType);
  } catch (e){}
}

return false;

It also uses ws://. instead of ws://null which might solve the first reported issue.

@GregTurner

@benfoxall Likely it would cause problems for non-secure connections... I just wanted add a little info for the maintainers. Since Chrome 36 is warning users now, this increases the issues critically.

I like your protocol switching suggestion... what does the '.' mean in URL speak anyways?

@cmarrero01

I have the same issue and I can't solve this with any suggested idea above. Where I need put this:

var protocol = 'https:'==location.protocol?'wss':'ws',
protoBin;

if('WebSocket' in window) {
if( protoBin = 'binaryType' in WebSocket.prototype ) {
return protoBin;
}
try {
return !!(new WebSocket(protocol+'://.').binaryType);
} catch (e){}
}

return false;

In order that my code works?.

@pfee

Looking through the current version of binary.js:
https://github.com/binaryjs/binaryjs/blob/ed1c11bc3821ba1e88321f980eb1cae2b5fd86ff/dist/binary.js

I see binaryFeatures has three properties:

  • useBlobBuilder
  • useArrayBufferView
  • supportsBinaryWebsockets

The issue here relates to browsers issuing warnings on the JavaScript console due to this line:
var wstest = new WebSocket('ws://null');

The first two properties are used elsewhere within binary.js, so their existance is justified. However I see no other reference to supportsBinaryWebsockets. Therefore is this feature test necessary at all? Can this bug be solved by simply deleting this code or is binaryFeatures.supportsBinaryWebsockets part of the external API that's used by other modules?

Can this particular feature test be removed?


binaryFeatures.supportsBinaryWebsockets = (function(){
  try {
    var wstest = new WebSocket('ws://null');
    wstest.onerror = function(){};
    if (typeof(wstest.binaryType) !== "undefined") {
      return true;
    } else {
      return false;
    }
    wstest.close();
    wstest = null;
  } catch (e) {
    return false;
  }
})();
@noamtcohen noamtcohen referenced this issue in noamtcohen/AudioStreamer
Closed

no recording #1

@rgymaster

if wstest was created, it will not be closed, the code

wstest.close();
wstest = null; 

does not work, if we close the wstest, the error will be not critical
WebSocket connection to 'ws://null/' failed: WebSocket is closed before the connection is established.
instead of
WebSocket connection to 'ws://null/' failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED
it was tested on

    binaryFeatures.supportsBinaryWebsockets = (function(){
        var wstest, res;
        try {
            wstest = new WebSocket('ws://null');
            res = typeof(wstest.binaryType) !== "undefined";
            wstest.close();
            wstest = null;
        } catch (e) {
            res = false;
        } finally{
            return res;
        }
    })();
@soleilnoirmedia

The function supportsBinaryWebsockets is part of js-binarypack, a dependency of binaryjs.
Currently, binaryjs uses version 0.0.7 of said dependency. By version 0.0.9 the unused test has been removed.
By updating binaryjs to use a more recent version of that dependency (0.0.9 vs 0.0.7), all issues related to ws://null can be resolved, as well as some issues related to running this library on a site using a secure connection (i.e. https).

@soleilnoirmedia

I have opened a pull request to update js-binarypack dependency:
binaryjs/binaryjs/pull/95
Otherwise I have forked the repository for personal use while the pull request is discussed:
soleilnoirmedia/binaryjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.