eventsocket
Event socket
Install
$ npm install eventsocket
Usage
var EventSocket = require('eventsocket');
Methods
EventSocket(options)
EventSocket(port, [host])
EventSocket(path)
Create new event socket. Same as net.connect
.
var socket = new EventSocket(7000, '127.0.0.1');
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
connect(port, [host])
connect(path)
Same as net.Socket.connect
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
error
Emitted when net.Socket emit error.
Error events are treated as a special case in node. If there is no listener for it,
then the default action is to print a stack trace and exit the program.
see more.
newListener, removeListener
Inherited from EventEmitter.
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