mpubsub

0.0.1 • Public • Published

mPubsub

Built pubsub servers and clients using pure node.js

Install

$ npm install mpubsub

Usage

Setup

var mPubsub=require('mpubsub');   

Server side

First you should start the pub-sub server

mPubsub.createServer('127.0.0.1',4455);   //create a server at ip:127.0.0.1 and port:4455

Client side

Once you start the server , you can connect to the serve and share the pub-sub

//connect to the server (IP:127.0.0.1,port:4455);
mPubsub.connect('127.0.0.1', 4455, function(socket) {
 
    //SUB
    //sub a channel
    //scoket.sub(channel,callback)
    socket.sub('abc1', function(data) {
     //when somebody publish something in channel 'abc',the following will work
        console.log('sub data', data);
    });
 
    //UNSUB
    //unsub a channel
    //socket.unsub('channel');
    socket.unsub('abc2');
 
    //PUBLISH
    //pub something to channel abc
    //scoket.pub(channel,data)
    socket.pub('abc', '123asd');
 
    //END
    socket.end();
 
});

Readme

Keywords

Package Sidebar

Install

npm i mpubsub

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • zhuwenlong