var http = require('http');
var server = http.createServer();
server.on('request', function(req, res) {
res.setHeader('Content-Type', 'text/plain');
res.end('hello world');
});
server.on('upgrade', function(req, socket, head) {
console.log('upgrading');
socket.write('upgraded');
socket.on('data', function() {
console.log(arguments);
});
});
server.listen(3000);
in the chrome console:
var ws = new WebSocket('ws://localhost:3000);
ws.onopen = function() {
ws.send('hello');
};
Except console.log('upgrading') there is no output at all.
The browser waits on a http response (it shows me pending and no response available).
The question is just how I could send one without a request obj supplied to the callback?