ruby-on-railsrubywebsocketfaye

Faye websocket - 200 error


I'm building an app that supports realtime bid using Faye-websocket. But I got this 200 error and I have no idea what problem it is.

Error:

WebSocket connection to 'ws://localhost/auctions/3' failed: Error during WebSocket handshake: Unexpected response code: 200

SocketConnection.rb

require 'faye/websocket'

require 'websocket/extensions' require 'thread' require 'json'

class SocketConnection KEEPALIVE_TIME = 15 # in seconds

def initialize app 
    @app     = app 
end

def call env
    @env = env

    if Faye::WebSocket.websocket?(env)
        socket = Faye::WebSocket.new env

        socket.ping 'Mic check, one, two' do
          p [:ping, socket.object_id, socket.url]
        end

        socket.on :open do |event|
            p [:open, socket.object_id, socket.url]
            p [:open, socket.url, socket.version, socket.protocol]
        end

        socket.rack_response

    else
        @app.call(env)
    end
end

end


Solution

  • I firgured out the problem. It requires a server to support socket connection. In my case, I use thin server. All errors are fixed