Ruby wamp-client gem - 与crossbar.io的连接

时间:2016-02-01 09:09:04

标签: ruby websocket rubygems crossbar wamp-protocol

我是Ruby的新手

我正在尝试使用wamp-client gem建立与crossbar.io路由器的连接。 Crossbar具有通过交叉开关模板创建的所有默认设置和应用程序(python作为后端)。当我通过浏览器进行连接时,一切都很好但是当我尝试使用红宝石时只需

require  "wamp/client"
wamp_test = WAMP::Client.new("ws://127.0.0.1:8080") 
wamp_test.open

我有一个`handle_opening_handshake_response':未处理的打开握手响应#(Net :: WS :: Error)'错误。 我知道要处理握手我的WAMP路由器应该发送HTTP 101交换机协议,但它没有这样做(在wireshark中看不到它)。 请帮帮我。

客户请求:

GET / HTTP/1.1\r\n
Upgrade: websocket\r\n
Connection: Upgrade\r\n
Sec-Websocket-Key: RggxGCwmcnVuEB08UQMCWA==\r\n
Sec-Websocket-Version: 13\r\n
Sec-Websocket-Protocol: \r\n
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\n
Accept: */*\r\n
User-Agent: Ruby\r\n
Host: localhost:8080\r\n
\r\n
Full request URI: http://localhost:8080/
HTTP request 1/1

路由器返回:

HTTP/1.1 200 OK\r\n
Server: Crossbar/0.11.1\r\n
Date: Mon, 01 Feb 2016 07:48:33 GMT\r\n
Cache-Control: max-age=43200, public\r\n
Expires: Mon, 01 Feb 2016 19:48:33 GMT\r\n
Accept-Ranges: bytes\r\n
Content-Length: 5085\r\n
Content-Type: text/html\r\n
Last-Modified: Thu, 28 Jan 2016 13:07:24 GMT\r\n
\r\n
HTTP response 1/1
Line-based text data: text/html

1 个答案:

答案 0 :(得分:0)

使用默认(生成的)Crossbar.io配置时,请尝试:ws://127.0.0.1:8080/ws而不是ws://127.0.0.1:8080。 WAMP-WebSocket传输位于子路径上。

您可以在浏览器中打开http://127.0.0.1:8080http://127.0.0.1:8080/ws进行检查。

另外:您的客户端不发送有效的WebSocket子协议列表(Sec-Websocket-Protocol为空)。 Crossbar.io有一个配置选项,可以接受(并假设wamp.2.json),但更好的行为是激活WebSocket客户端库中的WebSocket子协议协商。