eventsocket
Event socket
Install
$ npm install eventsocket
Usage
var EventSocket = require('eventsocket');
Methods
EventSocket(ip, port)
Create new event socket from ip and port.
var socket = new EventSocket('127.0.0.1', 7000);
EventSocket(socket)
Create new event socket from existingnet.Socket
or JsonSocket
var net = require('net');
var server = net.createServer(function (con) {
var socket = new EventSocket(con);
}
emit(eventType, args...)
Send event over socket.
socket.emit('message',{foo: 'bar'});
disconnect()
Destroy connection
on(eventType, listener)
Inherited from events.EventEmitter
Events
connect
Emitted when socket connected (only when you pass ip, port).
disconnect
Emitted when disconnected.
Custom
Emitted event from peer
Logging
You can enable logging. See more
node test.js
DEBUG=EventSocket:connection node test.js
DEBUG=EventSocket:data node test.js
DEBUG=EventSocket:* node test.js
Protocol
We send json objects over socket then write one \0
. This is c/c++ friendly protocol. :smile:
Json object has name
and args
property. name
must be string and args
must be array.
{"name":"message","args":[{"foo":"bar"}]}\0