简体   繁体   中英

JavaScript and WebSockets: using specific protocol

I'm currently working with WebSockets and a PHP server: it works very well with Google Chrome and Opera, but not with Firefox 6.

I think it's due to the protocol version this last uses: I see somewhere that it uses the seventh version, whereas it's an older one for Google Chrome and Opera.

So, I modified my server code in order to manage this new version: by hashing the secure-key with 258EAFA5-E914-47DA-95CA-C5AB0DC85B11 and other stuffs, Firefox succeeds to connect. But if another client wants to connect (even another Firefox), the first one with Firefox deconnects itself.

I saw that buffer received by socket_recv() is either empty or hashed...

So I decided to skip the idea of managing the protocol used by Firefox 6 (there are no documentation on Internet... !): I think it could be easier to specify the protocol to use directly in JavaScript.

On this page they say that we can write this:

var mySocket = new WebSocket("http://www.example.com/socketserver", "my-custom-protocol");

But what should we write instead of "my-custom-protocol" in order to use the protocol managed by Google Chrome and Opera?

Thanks in advance!

The protocol option to the WebSocket constructor is really a "sub-protocol" (it is often called by that name) and it is an application level sub-protocol. It does not have any effect on the actual WebSocket protocol version. Browsers basically support a single version of the WebSocket protocol itself. Most servers support several versions of the protocol.

Firefox 6.0 introduced support for the new HyBi series of protocols (HyBi-00 is really just a copy of the Hixie-76 protocol). The HyBi versions introduce a new framing format for data and are not just a change to the handshake. Chrome 14 also uses the new HyBi protocol series.

Here is the most recent version of the WebSockets protocol: http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-14 although firefox 6.0 is actually this one http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-07 but there aren't really that many real changes (mostly textual changes to the spec itself).

Are you certain that firefox is connecting successfully (ie do you actually get an onopen event in the browser)?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM