tips

WebSocket very basic protocol debugging overview

1. Required tools

  • netcat
    brew install netcat
  • nodejs
    brew install node
  • websocket tools
    npm install websocket-upgrade
  • Chrome browse

2. Starting netcat as "server" on localhost, port 8080

$ nc -lcvv localhost 8080

3. Creating websocket using chrome developer console

var ws = new WebSocket('ws://localhost:8080');
ws.onconnect = function() { console.log('connected'); }
ws.onclose = function() { console.log('closed'); }
ws.onmessage = function(msg) { console.log(msg); }

4. Chrome to Netcat HTTP Request

GET / HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: localhost:8080
Origin: https://www.google.ch
Pragma: no-cache
Cache-Control: no-cache
Sec-WebSocket-Key: DqZ/oiDTOMxe2cvqs8tdZw==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits, x-webkit-deflate-frame
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36

5. Preparing response to chrome

$ node
> var wsupgrade = require('websocket-upgrade');
> var accept = wsupgrade.generateAccept('DqZ/oiDTOMxe2cvqs8tdZw==');
> console.log(accept);
dKCEqNbigQP0rJ2YtbTx89wt5vw=

6. Netcat to chrome HTTP Response

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: dKCEqNbigQP0rJ2YtbTx89wt5vw=
<CRLF>
<CRLF>

7. Chrome should notify in console

connected

8. Sending message from chrome to netcat over websocket

ws.send('hello');
chrome-netcat

 

9. Useful resources

Comments

Related posts

Art 3D/VR challenge - week 1 - abstract overview

Previous weekNext weekIntroduction This article is continuation of Art 3D/VR challenge. Please note, I don't describe all possible technologies, knowledge, science, models, and approaches you can find on the search engine. Index Abstract segments The chart above shows the most important 6…

0

Mongo MMS API agent for ruby with basic cli client

During last two days I have developed very minimalistic the Mongo MMS API ruby client which is easily extendable as mms-api gem (source code on github so please contribute). The client is used by me to extend Pulsar (capistrano) tasks…

0