Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dgram-stream

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dgram-stream

udp messages as a stream of objects

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

dgram-stream - udp as a duplex stream

What!? a dgram stream? You're crazy.

Yep, I am.

Usage

npm install dgram-stream

Write "packets" like:

{
  "to": {port: 1234}
  "payload": new Buffer("my data"),
}

Get "packets" like:

{ from: { address: '127.0.0.1', family: 'IPv4', port: 55230, size: 11 },
  payload: <Buffer 6d 79 20 64 61 74 61> }

Example:

var dgram = require('dgram')
var dgrams = require('dgram-stream')

// setup two (duplex) streams. use type or socket.
var one = dgrams('udp4')
var two = dgrams(dgram.createSocket('udp4'))

// bind to ports. both ways work the same.
one.sock.bind(1234)
two.bind(1235)

// data handlers
one.on('data', function(item) {
  console.log('one got: ' + item)
})

two.on('data', function(item) {
  console.log('two got: ' + item)
})

// try it out!
one.write({ to: { port:1235 }, payload: 'beep' })
two.write({ to: { port:1234 }, payload: 'boop' })

More at:

  • example1.js - simple example
  • example2.js - stdin -> udp send -> udp recv -> stdout

Keywords

FAQs

Package last updated on 31 May 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc