Archive for April, 2011

Small Survival guide when debugging your Comet/WebSocket application.

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 -> [AP]
GET /atmosphere-jquery-pubsub/pubsub/chat HTTP/1.1.
Upgrade: WebSocket.
Connection: Upgrade.
Sec-WebSocket-Key1: Z      mZ1  4 9 0W75 50!p13.
Sec-WebSocket-Key2: .mx1674Dy@ 69K  %K027C9:m.

T -> [AP]
HTTP/1.1 101 WebSocket Protocol Handshake.
Upgrade: WebSocket.
Connection: Upgrade.

T -> [AP]

Using curl

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

Without the -N option any real time update will not get display live in the console:

curl -N
<!--                                                              -->
<!-- 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!

Categories: Atmosphere, Comet, Websocket