Last active
April 2, 2019 15:22
-
-
Save yoshuawuyts/e184f8c2702a051526df13628f2fd21d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/node | |
let dgram = require('dgram') | |
let socket = dgram.createSocket('udp4', (msg, rinfo) => { | |
let peer = `${rinfo.address}:${rinfo.port}` | |
socket.send(msg, peer, (err) => { | |
if (err) peer.close() | |
console.log(`Sent ${rinfo.size} of ${rinfo.size} bytes to ${peer}`) | |
}) | |
}) | |
socket.bind(8080, () => { | |
let address = socket.address() | |
console.log(`Listening on ${address.address}:${address.port}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We're trying to show a realistic depiction of how people would likely write a UDP server in Node. This is how I'd go about it if I was tasked with building a UDP server for a contract.