Skip to content
/ punt Public
forked from tj/punt

Elegant UDP messaging for nodejs

Notifications You must be signed in to change notification settings

infonaut/punt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Punt

A small layer on top of node's core UDP module to make fast volatile messaging even simpler. Punt uses the tiny AMP prototol to serialize buffer, string, and json arguments.

Installation

$ npm install punt

Example

A small in-proc example of a server with three clients:

var punt = require('punt');
var server = punt.bind('0.0.0.0:5000');
var a = punt.connect('0.0.0.0:5000');
var b = punt.connect('0.0.0.0:5000');
var c = punt.connect('0.0.0.0:5000');

server.on('message', function(msg){
  console.log(msg);
});

setInterval(function(){
  a.send({ hello: 'world' });
}, 150);

setInterval(function(){
  b.send('hello world');
}, 150);

setInterval(function(){
  c.send(new Buffer('hello'));
}, 150);

yielding:

<Buffer 68 65 6c 6c 6f>
hello world
{ hello: 'world' }
<Buffer 68 65 6c 6c 6f>
hello world
{ hello: 'world' }
...

API

Server(addr)

Bind to the given addr.

Client(addr)

Connect to the given addr.

Client#send(...)

Send one or more arguments a single atomic message. The following types are supported through AMP:

  • strings
  • buffers
  • objects (serialized as JSON)

License

MIT

About

Elegant UDP messaging for nodejs

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.0%
  • Makefile 1.0%