4.0.0 • Published 8 years ago
geberel v4.0.0
Geberel
An IPC library uses UNIX domains.
Server
const Geberel = require('geberel');
const options = { path: '/tmp/geberel.sock' };
const server = new Geberel.server(options);
server.on('error', function (error) {
console.log(error);
});
server.on('connect', function (socket) {
socket.on('error', function (error) {
console.log(error);
});
socket.when('test', function (data) {
console.log(data); // { hello: 'people' }
});
socket.respond('async', function (data, done) {
setTimeout(function () {
data.foo = 'bar';
done(data);
}, 1000);
});
});
server.open();Client
const Geberel = require('geberel');
const options = { path: '/tmp/geberel.sock' };
const client = new Geberel.client(options);
client.on('error', function (error) {
console.log(error);
});
client.on('connect', function (socket) {
client.on('error', function (error) {
console.log(error);
});
socket.relay('test', { hello: 'people' }, function (error) {
// triggers the test event
});
socket.request('async', { hello: 'world' }, function (error, data) {
console.log(data); // { hello: 'world' , foo: bar }
});
});
client.open();API
Geberel.server(options, callback)
Extends the Events.EventEmitter class.
options: Object-path: StringUNIX domain socket path. (Default: /tmp/geberel.sock) -allowHalfOpen: BooleanIndicates whether half-opened TCP connections are allowed. (Default: false) -pauseOnConnect: BooleanIndicates whether the socket should be paused on incoming connections. (Default: false) -socket: Object-autoClose: BooleanDefaults to true. -allowHalfOpen: BooleanIndicates whether half-opened TCP connections are allowed. (Default: false) -readable: BooleanAllow reads on the socket when an fd is passed, otherwise ignored. (Default: false) -writable: BooleanAllow writes on the socket when an fd is passed, otherwise ignored. (Default: false) -fd: NumberIf specified, wrap around an existing socket with the given file descriptor, otherwise a new socket will be created.close: Functionopen: Function- Events - error - open - close - connect
Geberel.client(options, callback)
Extends the Events.EventEmitter class.
options: Object-socket: Object-autoClose: BooleanDefaults to true. -path: StringUNIX domain socket path. (Default: /tmp/geberel.sock) -fd: NumberIf specified, wrap around an existing socket with the given file descriptor, otherwise a new socket will be created. -allowHalfOpen: BooleanIndicates whether half-opened TCP connections are allowed. (Default: false) -readable: BooleanAllow reads on the socket when an fd is passed, otherwise ignored. (Default: false) -writable: BooleanAllow writes on the socket when an fd is passed, otherwise ignored. (Default: false) -fd: NumberIf specified, wrap around an existing socket with the given file descriptor, otherwise a new socket will be created.close: Functionopen: Function- Events - end - drain - error - open - close - connect - timeout
Geberel.socket(socket[, options])
Extends the Events.EventEmitter class.
socket: Net.Socketoptions: Object-unref: BooleanDefaults to false. -encoding: StringDefaults to utf8. -autoClose: BooleanDefaults to true.when: Function-event: String-callback: Function-data: Object, ArrayParsed usingJSON.parse.respond: Function-event: String-callback: Function-done: FunctionAccepts data to send back toSocket.request. -data: Object, ArrayParsed usingJSON.parse.relay: Function-event: String-data: Object, ArrayStringified usingJSON.stringify. -callback: Functionrequest: Function-event: String-data: Object, ArrayStringified usingJSON.stringify. -callback: Function- Events - end - error - close
Authors
License
Why You Should Choose MPL-2.0 This project is licensed under the MPL-2.0 License