postrank-labs / goliath

Goliath is a non-blocking Ruby web server framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebSocket connection fails: one ore more reserved bits are on

mindware opened this issue · comments

The websocket example, currently fails on a fresh ubuntu machine, when using chrome.

WebSocket connection to 'ws://localhost:9000/ws' failed: One or more reserved bits are on: reserved1 = 1, reserved2 = 0, reserved3 = 0

Additional info:
Using ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
Using em-websocket (0.3.8)
Using goliath (1.0.3)
Using eventmachine (1.0.3)
Using em-synchrony (1.0.3)

I think I've tracked the error down to the following:

  1. Your class name has to be Websocket. You cannot rename it to anything else or you'll get this error. ie:
    If you change the class's name from:
    class Websocket < Goliath::WebSocket
    to:
    class Server < Goliath::WebSocket
    You'll have the error.
  2. You cannot have your class in a module:
    module Test
    class Websocket < Goliath::WebSocket
  3. You need a "config" folder in your directory, with a filed called websocket.rb, including something similar to:
    config['channel'] = EM::Channel.new

Hey @mindware

So as you identified the websocket connection is dieing because of a server side issue I am guessing you are seeing something like the following in your server logs:

[26027:ERROR] 2013-10-12 12:16:44 :: undefined method `channel' for #
[26027:ERROR] 2013-10-12 12:16:44 :: ~/Development/goliath/lib/goliath/env.rb:149:in `method_missing'
examples/websocket.rb:21:in `on_open'

As you identified the config step is required for the websocket example. You can have your class inside a module, the config file that is expected for.

module Test
class Websocket < Goliath::WebSocket

would be
config/test_websocket.rb

This is config in the example is intended as the channel that you are using to send the message is going to be specific to your application. For example a EM::Channel will be local to that process, if you were writing a websocket based chat client that was served from n goliath processes you would want to instead use something like redis with pub/sub.

I believe this is the issue that you are seeing but I may be mistaken, as I am making some assumptions as there is no sample code.

Perhaps splitting each of the examples out into their own directory would make it clearer what is required for each example? I believe there are some files that are used across examples tho that would need to be duplicated to do this. Also open to other suggestions or leaving it as is.

i had the same issue, maybe a warning "config file is not found at the specified location" would be enough

@nolman
Thanks for the input, it was very helpful.