-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.cjs
More file actions
30 lines (26 loc) · 779 Bytes
/
Copy pathindex.cjs
File metadata and controls
30 lines (26 loc) · 779 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
const { log } = require('node:console');
const { chmod } = require('node:fs');
const net = require('node:net');
let clients=[];
let server=net.createServer((socket)=>
{
clients.push(socket);
socket.write('Welcome to the chat/n');
socket.on('data',(chunk)=>{
let message=chunk.toString();
clients.forEach((client)=>
{
if(clients.indexOf(client)!=clients.indexOf(socket))
client.write(`client says: ${message}\n`);
})
})
socket.on('end',()=>
{
clients.splice(clients.indexOf(socket),1);
console.log('one of the client disconnected\n');
});
});
server.listen(1337,()=>
{
console.log('listening from port 1337\n');
})