New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mock-dgram

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-dgram

Mock UDP socket using object streams

  • 0.1.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

mock-dgram

Mock UDP socket using object streams

Build Status

Example

var MockDgram = require('mock-dgram');

var md = new MockDgram();

var msgIn = {
  ip: { src: '1.1.1.1' },
  udp: { srcPort: 52, dataLength: 500 }
  data: new Buffer(500)
};

md.on('message', function (buf, rinfo) {
  test.deepEqual(msgIn.data, buf);      // true
  rinfo.address === msgIn.ip.src;       // true
  rinfo.port === msgIn.udp.srcPort;     // true
  rinfo.size === msgIn.udp.dataLength;  // true
});
md.input.write(msgIn);

var bufOut = new Buffer(100);
var portOut = 52;
var addressOut = '1.1.1.1';

md.send(bufOut, 0, bufOut.length, portOut, addressOut);

var msgOut = md.output.read();

test.deepEqual(bufOut, msgOut.data);    // true
msgOut.ip.dst === addressOut;           // true
msgOut.udp.dstPort === portOut;         // true

Description

Provide a mock implementation of the dgram.Socket API.

Inject data into the mock using the input PassThrough stream. This data will then be emitted via the 'message' event.

Receive data passed to the send() function by reading from the output PassThrough stream.

Keywords

FAQs

Package last updated on 15 Mar 2013

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