Skip to content

Client and server utilities for chunked UDP messaging, inspired by GELF+UDP

Notifications You must be signed in to change notification settings

shanewholloway/node-chunked-udp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chunked-udp

Client and server utilities for chunked UDP messaging, inspired by GELF+UDP

example client

const {udp_json_client} = require('chunked-udp');

const client = udp_json_client('udp://127.0.0.1:41234')

client.send({msg: 'someJsonDoc', answer: 42, nested: {args: [7,3,2], op:'*'}})

Or you can pass port and address down explicitly:

const client = udp_json_client({address: '127.0.0.1', port: 41234})

example server

const {createSocket} = require('dgram');
const server = createSocket('udp4')
  .on('message', (packet, rinfo) => {
      msg_parse_context(packet, rinfo);
    })
  .on('listening', () => {
      const {address, port} = server.address()
      console.log(`server listening ${address}:${port}`)
    })
  .bind(41234)


const {udp_json_parser} = require('chunked-udp');
const inflightMessages = new Map() // or, perhaps, require('hashbelt').createCachingHashbelt().autoRotate()
const msg_parse_context = udp_json_parser(inflightMessages, on_udp_message);

function on_udp_message(err, msg, rinfoList) {
  if (err)
    console.log('on_message ERROR', err);
  else console.log('on_message', msg);
}

About

Client and server utilities for chunked UDP messaging, inspired by GELF+UDP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published