JavaScript和WebSockets:使用特定协议 [英] JavaScript and WebSockets: using specific protocol

查看:132
本文介绍了JavaScript和WebSockets:使用特定协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用WebSockets和PHP服务器:它适用于Google Chrome和Opera,但不适用于Firefox 6.

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

我认为它应该到期到最后一个使用的协议版本:我看到它使用的是第七个版本,而对于谷歌Chrome和Opera来说它是旧版本。

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.

所以,我修改了我的服务器用于管理此新版本的代码:通过使用 258EAFA5-E914-47DA-95CA-C5AB0DC85B11 和其他内容对安全密钥进行哈希处理,Firefox成功连接。
但是如果另一个客户想连接(甚至是另一个Firefox),第一个用Firefox连接自己。

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.

我看到socket_recv()收到的缓冲区是空的或散列的......

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

所以我决定跳过管理Firefox 6使用的协议的想法(互联网上没有文档......!):我认为可以更容易指定直接在JavaScript中使用的协议。

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 这个页面他们说我们可以这样写:

On this page they say that we can write this:

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

但我们应该写什么而不是my-custom-protocol为了使用谷歌Chrome和Opera管理的协议?

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

提前致谢!

推荐答案

WebSocket构造函数的协议选项实际上是一个子协议(通常由该名称调用),它是一个应用程序级子协议。它对实际的WebSocket协议版本没有任何影响。浏览器基本上支持单个版本的WebSocket协议本身。大多数服务器都支持多种版本的协议。

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引入了对新HyBi系列协议的支持(HyBi-00实际上只是Hixie-76协议的一个副本) )。 HyBi版本为数据引入了新的帧格式,而不仅仅是对握手的改变。 Chrome 14还使用了新的HyBi协议系列。

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.

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

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).

你确定firefox是连接成功(即你实际上是否在浏览器中获得了一个onopen事件)?

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

这篇关于JavaScript和WebSockets:使用特定协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆