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

dgram-server

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dgram-server

Stream-based UDP server.

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

dgram-server

Build Status npm node license downloads Coverage Status code style

Stream-based UDP server.

Doesn't properly work with cluster.

Usage

const dgramsrv = require('dgram-server')

const server = dgramsrv.createServer()

server.on('socket', (socket) => {
  socket.on('data', (data) => {
    console.log('got %s bytes from %s:%s', data.length, socket.remoteAddress, socket.remotePort)

    socket.write('hello, world!', () => {
      socket.close()
    })
  })
})

server.listen(() => {
  console.log('udp server started on 0.0.0.0:%s', server.address().port)
})

API

  • createServer([options: Object]): Server

Creates a new UDP server. Also accept all options for dgram.createSocket(). If options.socket is provided, these options will be ignored.

  • option.socket: dgram.Socket

An optional internal dgram socket used as transport layer.

  • class Server

This class is used to create a UDP server. Server is an EventEmitter with the following events:

  • Event: 'socket'
    • socket: unicast.Socket

Emitted when a new association is made. socket is an instance of unicast.Socket.

  • Event: 'listening'

Emitted when the server has been bound after calling server.listen()

  • server.listen([port: number[, host: string]][, callback: function])
  • server.listen()

Start a server listening for associations. When the server starts listening, the 'listening' event will be emitted. The last parameter callback will be added as a listener for the 'listening' event.

  • server.close()

Close the underlying socket and stop listening for data on it.

  • server.address(): Object

Returns the bound address, the address family name, and port of the server as reported by the operating system. Useful to find which port was assigned when getting an OS-assigned address. Returns an object with port, family, and address properties: { port: 12346, family: 'IPv4', address: '127.0.0.1' }.

Don't call server.address() until the 'listening' event has been emitted.

  • server.connections: number

The number of concurrent associations on the server.

  • unicast - Unicast implementation of UDP Datagram sockets.

License

MIT, 20!8 (c) Dmitriy Tsvettsikh

Keywords

FAQs

Package last updated on 19 Feb 2018

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