Skip to content

Instantly share code, notes, and snippets.

@clowwindy
Created September 24, 2012 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clowwindy/3775537 to your computer and use it in GitHub Desktop.
Save clowwindy/3775537 to your computer and use it in GitHub Desktop.
node websockets
var srv = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('okay');
});
srv.on('upgrade', function(req, socket, head) {
socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
'Upgrade: WebSocket\r\n' +
'Connection: Upgrade\r\n' +
'\r\n');
// ...
});
var req = http.request({
host: '127.0.0.1',
headers: {
'Connection': 'Upgrade',
'Upgrade': 'websocket'
});
req.end();
req.on('upgrade', function(res, socket, upgradeHead) {
// ...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment