Websockets:Rachet &来自 npm 的高速公路兼容吗? [英] Websockets: Are Rachet & autobahn from npm compatible?

查看:28
本文介绍了Websockets:Rachet &来自 npm 的高速公路兼容吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试验 Ratchet php 库.特别是,我一直在尝试将他们的推送集成演示集成到 React 应用程序中.

I'm experimenting with the Ratchet php library. In particular, I've been trying to integrate their push integration demo into a React application.

他们的演示参考了,它与我的服务器实现相悖(几乎是他们演示的副本).

Their demo references a seemingly one-off version of the autobahn JS library, which works against my server implementation (a near duplicate of their demo).

但是,当我尝试使用 来自 npm 的 autobahn JS 时,一切都崩溃了.这似乎实现了更新版本的 Web Sockets 协议?

However, when I try to use autobahn JS from npm everything melts down. It seems this implementes a newer version of the Web Sockets protocol?

高速公路的一次性版本为 Sec-WebSocket-Protocol 标头传递 wamp,Ratchet 似乎支持该标头.高速公路的 npm 版本通过 wamp.2.json, wamp.2.msgpack...

The one-off version of autobahn passes wamp for the Sec-WebSocket-Protocol header, which Ratchet seems to support. The npm version of autobahn passes wamp.2.json, wamp.2.msgpack...

挖掘 Ratchet 代码,我发现了this

Digging through the Ratchet code I found this

如果堆栈中的任何组件支持 WebSocket 子协议返回每个都支持在一个数组中

If any component in a stack supports a WebSocket sub-protocol return each supported in an array

所以我在我的组件上实现了 Ratchet\WebSocket\WsServerInterface

So I implemented Ratchet\WebSocket\WsServerInterface as such on my component

public function getSubProtocols()
{
    return ['wamp.2.json', 'wamp.2.msgpack'];
}

现在连接尝试进一步进行,但仍然爆炸

Now the connection attempt gets a little further along, but still blows up

由于违反协议而导致传输失败:意外的消息类型 0

failing transport due to protocol violation: unexpected message type 0

然后客户端关闭连接失败

Then the client fails to close the connection

未捕获的 DOMException:无法在WebSocket"上执行关闭":代码必须是 1000 或 3000 到 4999 之间.1002 两者都不是.

Uncaught DOMException: Failed to execute 'close' on 'WebSocket': The code must be either 1000, or between 3000 and 4999. 1002 is neither.

这里发生了什么;Ratchet 是否支持旧版本的 Web Socket 协议,或者有没有办法让这两个库成功通信?

What's going on here; does Ratchet support an older version of the Web Socket protocol, or is there a way to get these two libraries talking successfully?

推荐答案

这两个库不兼容,根据 GitHub 上的这个问题.

The two libraries are not compatible, per this issue on GitHub.

Autobahn 0.9+实现wampv2,我们必须使用autobahn 0.8,我也没有在 npm 上找到它.相反,我发现 wamp1,但我还没有测试过.

Autobahn 0.9+ implements wampv2, we have to use autobahn 0.8, and I also don't find it on npm. Instead I find wamp1, but I haven't tested it yet.

这篇关于Websockets:Rachet &来自 npm 的高速公路兼容吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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