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

dgram-as-promised

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dgram-as-promised

Promisify dgram module

  • 3.0.2
  • Source
  • npm
  • Socket score

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

dgram-as-promised

Build Status Coverage Status npm

This module provides promisified version of standard dgram class. The API is the same as for standard dgram, except bind, close and send methods which return Promise object.

Requirements

This module requires ES6 with Node >= 6.

Installation

npm install dgram-as-promised

Additionally for Typescript:

npm install -D @types/node

Usage

dgram-as-promised can be used similar to standard dgram module.

Example:

const {DgramAsPromised} = require("dgram-as-promised")

const socket = DgramAsPromised.createSocket("udp4")

const MEMBERSHIP = "224.0.0.1"
const PORT = 41234

const message = Buffer.from("ABCDEFGH")

Typescript:

import DgramAsPromised from "dgram-as-promised"
// or
import {DgramAsPromised} from "dgram-as-promised"

const socket = DgramAsPromised.createSocket("udp4")

Method bind returns Promise object which resolves to address info when listening event is emitted.

const address = await socket.bind()
console.log(`Socket is listening on ${address.address}:${address.port}`)

socket.setBroadcast(true)
socket.setMulticastTTL(128)

socket.addMembership(MEMBERSHIP)
console.log("Membership is set")

Method send returns Promise object which is fulfilled when message has been sent.

const bytes = await socket.send(message, 0, message.length, PORT, MEMBERSHIP)
console.log(`Message is sent (${bytes} bytes)`)

Method close returns Promise object which resolves to number of bytes sent when close event is emitted.

await socket.close()
console.log("Socket is closed")

License

Copyright (c) 2016-2019 Piotr Roszatycki mailto:piotr.roszatycki@gmail.com

MIT

Keywords

FAQs

Package last updated on 10 Jul 2019

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