Socket
Socket
Sign inDemoInstall

mock-dgram

Package Overview
Dependencies
8
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mock-dgram

Mock UDP socket using object streams


Version published
Maintainers
1
Install size
129 kB
Created

Readme

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

Last updated on 15 Mar 2013

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc