Giter Site home page Giter Site logo

telepathymq's Introduction

telepathymq

a nodejs module for inter-process communication that let you share javascript object and events over network that support tcp and secure tls sockets.

npm version Build Status Coverage Status Dependencies Status

Installation

telepathymq is available over npm

npm install telepathymq

Sample

this code initialise connection between client and server side and send an "hello world" message

var Telepathy = require('telepathymq');

// initialise the server side
// the constructor take a string argument for the instance identity
// used to send data from other node.
// it must be uniq on connected nodes.
var server = new Telepathy('server');
server.listen(8060, function() {
  console.log('server is listening on port 8060');
});
server.on('register', function(identity) {
  console.log(identity + ' has registered on server');
});
server.on('message', function(msg) {
  console.log('message: ' + msg);
});

// initialise the client side
var client = new Telepathy('client');
client.register('server', 'tcp://localhost:8060');
client.on('register', function(identity) {
  console.log(identity + ' has registered on client');
  // emit an event called 'message' on 'server' with a string 'hello world' as data
  client.emit('server', 'message', 'hello world');
});

Methods

server.listen()

Start a server listening for connections. Possible signatures:

  • listen(port, [ip,] callback)
  • listen(url, options, callback)

server.listen(port, [ip,] callback)

port: integer tcp port number ip: string ip address (optional, default: '0.0.0.0') callback: function

server.listen(connectString, [options,] callback)

connectString: string {tcp | tls}://{ip | hostname}:{port} options: object see node tls.createServer options only use in tls protocol callback: function

client.register(identity, connectString, [options,] callback)

immediately initiates connection. When the connection is established, a 'register' event will be emitted on the client.

identity: string identity of server node connectString: string {tcp | tls}://{ip | hostname}:{port} options: object see node tls.connect options only use in tls protocol callback: function

node.emit(identity, eventName, data)

emit an event on identity node.

identity: string identity of the other side node. eventName: string the name of the event being emited data: string,object data being sent over event

node.on(eventName, listener)

Adds the listener function to the end of the listeners array for the event named eventName.

eventName: string the name of the event. listener: function

node.defer(identity, eventName[, data])

return an asynk promise and send an asynk deferred.

identity: string identity of the other side node. eventName: string the name of the event being emited data: string,object data being sent over event

server.on('myDefer', function(defer, data) {
  if (data.val === 1) {
    defer.notify('some data');
  }
});

var promise = client.defer('server', 'myDefer', {val: 1});
promise.progress(function(data) {
  console.log(data);
});

telepathymq's People

Contributors

atiertant avatar corvuscorrax avatar

Watchers

 avatar  avatar  avatar

Forkers

corvuscorrax

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.