Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I debug a websocket server

Tags:

websocket

I'm trying to write a server for a webSocket connection. I've read the spec (76, not 75) carefully. I'm using minefield as the browser.

When I try to create a WebSocket from javascript in the browser:

var ws = new WebSocket("ws://localhost:8766/hoho");

The browser responds with

"Firefox can't establish a connection to the server at ws://localhost:8766/hoho."

My server is getting a valid client handshake request, it sends back the response and then boom.

I've run every example handshake example I can find through my server and I match the given responses exactly in every instance. I'm pretty confident that the return byte stream is correct. I don't need help debugging my code, it's doing what I mean it to do. I need help debugging my use of the handshake protocol since when I give minefield what I think is a correct response it laughs at me.

My question is this: How can I debug this thing? I can think of two possibilities.

  1. Is there any way to get minefield to tell me WHY it's rejecting my handshake?

  2. Is there a working, public, webSocket server service on the web? If there is, I can proxy it, watch the byte streams in both direction and figure out where mine is different.

Does anyone have any ideas in these directions or any other ideas?

Thanks for any help.

like image 441
Joe Avatar asked Jul 02 '10 18:07

Joe


People also ask

How do I debug a WebSocket connection?

Open the URL http://localhost:8080 in Firefox. With the developer tools open, we now see an HTTP handshake. Click on the request to analyze the handshake: Under the Headers tab, we see request and response headers with protocol upgrades and other WebSocket headers.

How do I resolve a WebSocket connection error?

Solution 1Check that all the Bot Insight services are running. Check that your firewall settings are configured to accept incoming websocket data. Try to use a different web browser. Restart the Bot Insight Visualization and Bot Insight Scheduler services.


3 Answers

I'm in the process of debugging a similar situation, and the tool I'm relying on most is netcat, with some additional use of openssl. Shut down your websocket server and run nc -l 8766. That lets you record exactly what headers are being sent. Turn the websocket server back on and use nc 8766 to paste in those same headers and see the result. openssl s_client -connect localhost:443 will let you make the request with ssl, if that is in your mix.

From there, make sure the responses conform completely to the websocket handshake protocol. For instance, my problem right now is that my responses have Connection: close, which is no good.

like image 113
outofculture Avatar answered Sep 17 '22 07:09

outofculture


About the 2nd possibility. Yes, there is a websocket server out there. the jWebSocket demo server at http://jwebsocket.org/demos/chat/chat.htm

hope this helps

Added: Echo socket server at: http://www.websocket.org/echo.html

like image 20
Tom Klino Avatar answered Sep 17 '22 07:09

Tom Klino


Here's a jsfiddle that I made from http://www.websocket.org echo websocket server which works in Chrome but not in Firefox 6: http://jsfiddle.net/awDLc/

It is adjusted to use MozWebSocket rather than WebSocket, but perhaps that isn't enough?

like image 33
Jason Kleban Avatar answered Sep 17 '22 07:09

Jason Kleban