> If you send json over the wire, socket.io automatically converts it to a javascript object or array for you, ready to be used.
That's literally 4 lines
// sender
ws.send({event: JSON.stringify(someObject));
// receiver
ws.on('message', function(str) {
obj = JSON.parse(str);
});
> socket.emit("hello"); and the server can listen on this event with socket.on("hello").
This is hardly any more lines of code
// sender
function sendEvent(eventName, data) {
ws.send(JSON.stringify({event: eventName, data: data}));
}
// receiver
ws.on('message', function(str) {
var eventInfo = JSON.parse(str);
eventEmittier.emit(eventInfo.event, eventInfo.data);
});
Sure I'm glossing over a few things but EventEmitter is 10-20 lines depending on how crazy you want to get and wrapping both in a objects is probably another 10-20 lines
socket.io on the other hand is a C node.js plugin and 61000 lines of JS code :(