Skip to content

Instantly share code, notes, and snippets.

@lpinca
Created December 20, 2013 09:32
Show Gist options
  • Save lpinca/8052477 to your computer and use it in GitHub Desktop.
Save lpinca/8052477 to your computer and use it in GitHub Desktop.
Primus WebSocket not opened issue
'use strict';
var Ws = require('ws')
, ws = new Ws('ws://localhost:3000/primus');
ws.on('open', function() {
var buf = new Buffer([
0x88, // state.lastFragment = true && opcode = 8
0x02, // state.masked = false && length = 2
0x03, // this byte and the next => code = 1000
0xe8
]);
this._socket.write(buf); // cause WebSocket#close to be called
process.send('write to the spark');
});
'use strict';
var fork = require('child_process').fork
, server = require('http').createServer()
, Primus = require('primus')
, primus = new Primus(server, {transformer: 'websockets'});
primus.on('log', function(type) {
if (type === 'error') {
var err = arguments[1];
console.error(err.message);
}
});
server.listen(3000);
var child = fork(__dirname + '/client.js');
child.on('message', function() {
primus.forEach(function(spark) {
spark.write('foo');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment