简体   繁体   English

JavaScript和WebSockets:使用特定协议

[英]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. 我目前正在使用WebSockets和PHP服务器:它适用于谷歌Chrome和Opera,但不适用于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. 我认为这是由于最后一次使用的协议版本:我看到它使用的是第七版,而对于Google Chrome和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. 因此,我修改了我的服务器代码以管理这个新版本:通过使用258EAFA5-E914-47DA-95CA-C5AB0DC85B11和其他东西散列安全密钥,Firefox成功连接。 But if another client wants to connect (even another Firefox), the first one with Firefox deconnects itself. 但是如果另一个客户想要连接(甚至是另一个Firefox),那么第一个用Firefox连接自己。

I saw that buffer received by socket_recv() is either empty or hashed... 我看到socket_recv()收到的缓冲区为空或散列...

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. 所以我决定跳过管理Firefox 6使用的协议的想法(互联网上没有文档......!):我认为指定直接在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? 但是为了使用Google Chrome和Opera管理的协议,我们应该编写什么而不是“my-custom-protocol”

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. WebSocket构造函数的协议选项实际上是一个“子协议”(通常由该名称调用),它是一个应用程序级子协议。 It does not have any effect on the actual WebSocket protocol version. 它对实际的WebSocket协议版本没有任何影响。 Browsers basically support a single version of the WebSocket protocol itself. 浏览器基本上支持单个版本的WebSocket协议本身。 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). Firefox 6.0引入了对新HyBi系列协议的支持(HyBi-00实际上只是Hixie-76协议的一个副本)。 The HyBi versions introduce a new framing format for data and are not just a change to the handshake. HyBi版本为数据引入了新的帧格式,而不仅仅是对握手的改变。 Chrome 14 also uses the new HyBi protocol series. Chrome 14还使用了新的HyBi协议系列。

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). 这是WebSockets协议的最新版本: http//tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-14虽然firefox 6.0实际上就是这个http://tools.ietf.org/html / draft-ietf-hybi-thewebsocketprotocol-07但实际上没有那么多真正的变化(主要是对规范本身的文本更改)。

Are you certain that firefox is connecting successfully (ie do you actually get an onopen event in the browser)? 您确定firefox是否成功连接(即您实际上是否在浏览器中获得了一个onopen事件)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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