mirror of
https://github.com/m-lamonaca/dev-notes.git
synced 2025-04-06 02:46:39 +00:00
629 B
629 B
Net Module (Connection Oriented Networking - TCP/IP)
Server (net.Server
)
const net = require('net');
const server = net.createServer((socket) => { /* connect listener */ });
server.on('error', (err) => {
// handle error
});
server.listen(8124, () => { }); // listen for connection
Sockets (net.Socket
)
const client = net.createConnection({ host: "127.0.0.1", port: 8124 }, () => { /* 'connect' listener. */ });
socket.on("data", (buffer) => { /* operate on input buffer */ });
socket.on("error", (err) => { /* handle error */ });
socket.on("end", () => {}); // client disconnection