13

I'm getting started with websocket-rails, trying to convert an old polling system for notifications (on Ruby 2.1/Rails 4.0) to something a bit more modern with WS. I'm using WebsocketRails in standalone mode, here is my configuration, basically, the default:

WebsocketRails.setup do |config|
   config.standalone = true
end

I have also setup a fresh Redis running on the default port - there seems to be no communication issues here.

On the client side, I have added the websocket-rails's JS and when trying to open an connection and subscribe to a channel, with:

@dispatcher = new WebSocketRails "localhost:3001/websocket"
@channel = @dispatcher.subscribe "notifications"

I see an error in the Chrome console:

WebSocket connection to 'ws://localhost:3001/websocket' failed: Invalid frame header 

In Firefox, the error is different but still an error:

The connection to ws://localhost:3001/websocket was interrupted while the page was loading.

From the websocket server logs, I can see that a connection has been initiated and then dropped, but there are no other logs, even tho log level is "debug"... There are no other errors that I can see and a cursory Google search doesn't bring up anything regarding "invalid frame header", so I'm pretty much stuck.

Any help would be appreciated!

EDIT: I ended up using NodeJS+Faye to get things moving, and it has been working so well that I'm happy to introduce this new moving part in the system. I'm sure the issue was just something temporary based on my specific setup but sometimes, you just have to get things done.

Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
Enders
  • 708
  • 1
  • 4
  • 11
  • What webserver are you using? I'm using faye-websocket on thin and I'm in exactly the same situation. – itdoesntwork Dec 22 '14 at 02:53
  • It's running on Thin. I have since then upgraded to Rails 4.1 and Ruby 2.1.5 after the security updates and haven't had a chance to try again, I am hoping for a christmas miracle. I have looked around and couldn't find much about the issue so I assume it's just an artifact due to a very unlikely combination of elements. – Enders Dec 23 '14 at 01:01
  • If you're not using any special Rails features, you would probably find [the Plezi framework](https://github.com/boazsegev/plezi) easier to work with. It should work also with ActiveRecord and ActiveSupport if you're using them and it has easy Redis integration. – Myst Jun 03 '15 at 20:38

3 Answers3

7

I think you are looking for the following resources:

From the question thread: debugging websocket in google chrome

Chrome developer tools now have the ability to list WebSocket frames and also inspect the data if the frames are not binary.

Process:

  1. Launch Chrome Developer tools
  2. Load your page and initiate the WebSocket connections
  3. Click the Network Tab.
  4. Select the WebSocket connection from the list on the left (it will have status of "101 Switching Protocols".
  5. Click the Frames sub-tab. Binary frames will show up with a length and time-stamp and indicate whether they are masked. Text frames will show also include the payload content.

Theres also this (somewhat old) blog article from 2012: Inspecting WebSocket Traffic with Chrome Developer Tools

Community
  • 1
  • 1
Myst
  • 18,516
  • 2
  • 45
  • 67
  • 2
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/10618602) – Blackwood Dec 19 '15 at 05:08
  • @Blackwood - Thanks. Done :) – Myst Dec 19 '15 at 05:18
0

I think that there's something wrong with the format of the data being sent over the wire.

Carefully look at the format of the message. Has it been properly stringified? Do your brackets and parens, {}, [], and () all match? Did your IDE insert an extra somewhere? Try validating a message with a linter or an online validator.

Inspect the message on both the sender and receiver sides. Make sure that everything is correct.

kmiklas
  • 13,085
  • 22
  • 67
  • 103
0

This may not be the answer to the author's original question but I want to add a possible solution to this Invalid Frame Header error. From my small research, Invalid Frame Header can be generated on Websocket protocol when the server sends an empty response (message with 0 length). 0 length in TCP signals that connection has been closed and therefore any data transmission after the empty message fails. This is the link that helped me to find this solution. I hope someone in the future will find this useful and save some time.

klacek139
  • 13
  • 1
  • 4
  • 1
    This is NOT a link only answer. The author of this answer explains it and THEN mentions that the following link is what helped him figure this out. – Akshay Sehgal Jan 02 '21 at 20:47
  • Thank you, Akshay. I see a point in including all the details, though the referenced page has not changed in 10 years so it is unlikely to happen in the future. Though I will try to add all the details when I have time to do so. – klacek139 Jan 03 '21 at 13:36