Home > Atmosphere, Comet, Websocket > Small Survival guide when debugging your Comet/WebSocket application.

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

Categories: Atmosphere, Comet, Websocket
  1. August 7, 2012 at 5:57 am

    Nice post.
    Since you wrote this article, debugging WebSocket apps became easier than ever: http://blog.kaazing.com/2012/05/09/inspecting-websocket-traffic-with-chrome-developer-tools/

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: