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

udpsocket

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

udpsocket

informal udp module liked socket.io

0.0.1
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

udp socket

A module like socket.io but implement with udp protocol

In statard,websocket shoule be implement with tcp/http,this module just a exercise,so please not use it in production environment

usage - a simple chat server

server

'use strict'
const UdpSocket = require('ndpsocket').Server
const server = new UdpSocket();

const readline = require('readline');
const rl = readline.createInterface(process.stdin, process.stdout);

let cclient = null;
server.on('connecting', client => {
  cclient = client;
  console.log(`connect from ${client.rinfo.address}:${client.rinfo.port}`)
  client.on('message', msg => {
    console.log(msg)
  })
})


server.onListening(() => {
  console.log(`listen on ${JSON.stringify(server.socket.address())}`)
})

rl.on('line', (line) => {
  cclient.emit('message', line.trim());
})

server.socket.bind(43214);

client

'use strict'

const ClientSocket = require('ndpsocket').Client
const client = new ClientSocket({ address: 'localhost', port: 43214 })
const readline = require('readline');
const rl = readline.createInterface(process.stdin, process.stdout);

client.on('message', (m) => {
  console.log(m)
})

client.socket.on('listening', () => {
  console.log(client.socket.address().port)
})

rl.on('line', (line) => {
  client.emit('message', line.trim());
})

TO DO

ack

check server is alive

faster serialize

Keywords

udp

FAQs

Package last updated on 26 Sep 2016

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