Under my Atmosphere’s Project works, I’m getting a lot of questions about how to debug WebSocket/Comet applications. Here is some simple tools and trick I use.
A lot of people use wireshark, I much prefer using ngrep for snooping the network packet. As simple as:
sudo ngrep -d en0 -q -W byline port 8080
For WebSocket it helps seeing what’s being sent being the client and the server. Of course you can always use FireBug or Chrome dev tool for debugging inside the browser, but it is much easier IMO to see the interaction between the browser and the server from a terminal window:
T 127.0.0.1:61265 -> 127.0.0.1:8080 [AP] GET /atmosphere-jquery-pubsub/pubsub/chat HTTP/1.1. Upgrade: WebSocket. Connection: Upgrade. Host: 127.0.0.1:8080. Origin: http://127.0.0.1:8080. Sec-WebSocket-Key1: Z mZ1 4 9 0W75 50!p13. Sec-WebSocket-Key2: .mx1674Dy@ 69K %K027C9:m. . .TQ..34. T 127.0.0.1:8080 -> 127.0.0.1:61265 [AP] HTTP/1.1 101 WebSocket Protocol Handshake. Upgrade: WebSocket. Connection: Upgrade. Sec-WebSocket-Origin: http://127.0.0.1:8080. Sec-WebSocket-Location: ws://127.0.0.1:8080/atmosphere-jquery-pubsub/pubsub/chat. . T 127.0.0.1:8080 -> 127.0.0.1:61265 [AP] B...%...K....[..
If you are using curl to test your Comet application (or Websocket to test the initial handshake). make sure you pass the -N option as without, curl will buffer the server’s response and will not display it until the connection gets dropped by the server:
curl -N http://127.0.0.1:8080/atmosphere-jquery-pubsub/pubsub/chat
Without the -N option any real time update will not get display live in the console:
curl -N http://127.0.0.1:8080/atmosphere-jquery-pubsub/pubsub/chat <!-- http://github.com/Atmosphere --> <!-- Welcome to the Atmosphere Framework. To work with all the browsers when suspending connection, Atmosphere must output some data to makes WebKit based browser working.--> <!-- EOD -->
For any questions, use Twitter to reach me!