provide a very basic upd communication mechanism for nodejs
CoffeeScript
Permalink
Failed to load latest commit information.
lib to fix: diff processes send udp msg via same port Mar 21, 2014
src to fix: diff processes send udp msg via same port Mar 21, 2014
.gitignore working on unit test Mar 20, 2014
.travis.yml working on unit test Mar 20, 2014
LICENSE-MIT working on unit test Mar 20, 2014
README.md
package.json to fix: diff processes send udp msg via same port Mar 21, 2014
tests add implementation Sep 10, 2012

README.md

udpcomm

Provide a simple hub-like UPD datagram communication mechanism for NodeJs

This module includes 2 class:

  • UDPShoutor - send and receive messages from other shouters
  • UDPHub - a hub mechanism to distribute message from shouters

Install

Install the module with:

npm install udpcomm

Usage

// fire up the udp hub
(function() {
  var UDPHub, server;

  UDPHub = require("../udpcomm").UDPHub;

  server = new UDPHub(9999);

  server.start();

}).call(this);

// in another process, run the shouter
(function() {
  var PORT, UDPShoutor, channelId, onMessage, shoutor;

  UDPShoutor = require("../udpcomm").UDPShoutor;

  PORT = 9999;

  channelId = 5;

  onMessage = function(msg, rinfo) {
    return console.log("[client(" + process.pid + ")] msg:" + (msg.toString()) + ", from:" + rinfo.address + ":" + rinfo.port);
  };

  shoutor = new UDPShoutor(PORT, channelId, onMessage);

  setInterval(function() {
    var message;
    message = new Buffer("channelId:" + channelId + " pid:" + process.pid + ", time:" + (Date.now()));
    return shoutor.sendMessage(message);
  }, 1000);

}).call(this);


// in third process, run the same shouter
// and you will see how it work

License

Copyright (c) 2014 Yi Licensed under the MIT license.