Websockets: Are Rachet & autobahn from npm compatible?

谁说胖子不能爱 提交于 2019-12-11 08:01:19

问题


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

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?

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

Digging through the Ratchet code I found this

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

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

failing transport due to protocol violation: unexpected message type 0

Then the client fails to close the connection

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

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?


回答1:


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

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.



来源:https://stackoverflow.com/questions/48818453/websockets-are-rachet-autobahn-from-npm-compatible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!