-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
31 lines (25 loc) · 734 Bytes
/
app.js
File metadata and controls
31 lines (25 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// console.log("Hello, World!");
const net = require('net');
const clients = [];
const server = net.createServer((socket) => {
clients.push(socket);
console.log('Client connected');
socket.on('data', (data) => {
console.log('Received:', data.toString());
clients.forEach((client) => {
if (client !== socket) {
client.write(data);
}
});
});
socket.on('end', () => {
clients.splice(clients.indexOf(socket), 1);
console.log('Client disconnected');
});
socket.on('error', (err) => {
console.error('Socket error:', err);
});
});
server.listen(3000, () => {
console.log('Chat server started on port 3000');
});