Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tj/punt
Elegant UDP messaging for nodejs
https://github.com/tj/punt
Last synced: 1 day ago
JSON representation
Elegant UDP messaging for nodejs
- Host: GitHub
- URL: https://github.com/tj/punt
- Owner: tj
- Created: 2013-05-15T01:47:11.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2019-01-03T11:21:01.000Z (about 6 years ago)
- Last Synced: 2024-04-13T22:47:58.225Z (10 months ago)
- Language: JavaScript
- Size: 19.5 KB
- Stars: 343
- Watchers: 7
- Forks: 54
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
- awesome-github-repos - tj/punt - Elegant UDP messaging for nodejs (JavaScript)
README
# Punt
A small layer on top of node's core __UDP__ module to make fast volatile messaging even simpler.
Punt uses the tiny [AMP](https://github.com/visionmedia/node-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:
```js
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(Buffer.from('hello'));
}, 150);
```yielding:
```
hello world
{ hello: 'world' }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