faye / faye-websocket-ruby

Standards-compliant WebSocket client and server
Other
1.04k stars 96 forks source link

Unable to connect with faye-ws-ruby (1006), works with faye-ws-node #110

Closed grunetix closed 6 years ago

grunetix commented 6 years ago

Hi there, I am unable to connect to a (third-party) websocket server with faye-websocket-ruby, i.e. the connection won't even open. Connecting works when using faye-websocket-node, however. Frankly, I haven't been able to find any meaningful clues with debugging, so hoping you have an idea to solve this. Thanks for having a look!

faye-websocket-ruby (unable to open connection, returns 1006 error code):

  EventMachine.run {
    ws = Faye::WebSocket::Client.new("wss://ws.radarrelay.com/0x/v0/ws", nil, {})

    ws.on :open do |event|
      p 'connection opened'
    end

    ws.on :message do |event|
     p [:message, event.data]
    end

    ws.on :close do |event|
      p [:close, event.code, event.reason]
      ws = nil
    end
  }

note: connecting to another endpoint at the same host (wss://api.radarrelay.com/0x/v0/ws) [which is deprecated, however] also works with faye-websocket-ruby. Not sure what might cause the difference in behaviours between these two websocket endpoints.

faye-websocket-node (connects as expected):

var WebSocket = require('faye-websocket'),
    ws        = new WebSocket.Client('wss://ws.radarrelay.com/0x/v0/ws');

ws.on('open', function(event) {
    console.log('connection opened');
});

ws.on('message', function(event) {
    console.log('message', event.data);
});

ws.on('close', function(event) {
    console.log('close', event.code, event.reason);
    ws = null;
});
jcoglan commented 6 years ago

Hi there, I've run the script you provided in the environment as described and it prints:

"connection opened"
[:message, "{\"motd\":\"Hello and welcome to the RadarRelay API. Have a nice trade! 📡\",\"announcements\":[]}"]

Was this a temporary problem with the target server or are you still having a problem getting things working?

grunetix commented 6 years ago

James, thanks for checking this out.

I am still seeing the same behaviour - connecting to the target server (wss://ws.radarrelay.com/0x/v0/ws) works on my machine when using node, but doesn't using ruby:

[:close, 1006, ""]

Using the exact same (ruby) script, it connects successfully to their previous endpoint (wss://api.radarrelay.com/0x/v0/ws) - which however, is now deprecated.

I'm not really sure how to debug this, or what possible causes might be. Any suggestions on how I should investigate?

Appreciate your input!

jcoglan commented 6 years ago

I'd try to find out if there's anything in the transport layer that's failing; I suspect that either there's a problem with your ruby openssl bindings, or your computer doesn't trust the certificate issued by the server while mine does.

Find out if this method is being called; that means the TCP connection is established. Find out what the start_tls call in there is doing.

It might be worth re-installing ruby in case it needs recompiling against your system's openssl.

jcoglan commented 6 years ago

You could also try replacing the existing call with start_tls(:verify_peer => false) to skip checking the server's certificate. If that makes your program work then you know it's a trust issue.

grunetix commented 6 years ago

In the end, reinstalling ruby did the trick... I guess I got ahead of myself when trying to debug this.. Sorry about this! Thanks a lot for your input on this, James!