Skip to content

Commit 1c80a3d

Browse files
author
angelo.yanve
committed
feat: add UDP server implementation with dgram
1 parent 79c2417 commit 1c80a3d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

05-UDP/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import dgram from 'dgram'
2+
3+
const socket = dgram.createSocket('udp4')
4+
5+
socket.bind(5500, "127.0.0.1")
6+
7+
socket.on("message", (msg, info)=>{
8+
console.log(`New message: ${msg.toString()} from ${info.address}:${info.port}`);
9+
})

05-UDP/package.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "05-UDP",
3+
"version": "1.0.0",
4+
"description": "UDP server from scratch with nodejs",
5+
"main": "index.ts",
6+
"author": "onecode24",
7+
"license": "MIT",
8+
"dependencies": {
9+
"dgram": "^1.0.1"
10+
},
11+
"devDependencies": {}
12+
}

0 commit comments

Comments
 (0)