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.

ngrep.sourceforge.net

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....[..

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

About these ads
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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 50 other followers

%d bloggers like this: