I am beginner in nodejs and i want to create a simple program that print received massage from client side until user enter '.exit'. but nothing is printed in server side, until the user enters the '.exit' and all the sent messages are printed together
client.js
const net = require('node:net');
const rl = require("readline-sync")
const socket = net.createConnection({
port: 37373,
host: '127.0.0.1'
})
let input = rl.question('-->');
while(input !== '.exit'){
socket.write(input);
input = rl.question('-->')
}
server.js
const server = net.createServer()
server.on("connection", socket =>{
socket.on('data', (data)=> {
const datastring = data.toString('UTF-8')
console.log(datastring)
})
})
server.listen(port, host);
when i enter this inputs in client side:
--> one
--> two
--> three
-->.exit
the output of server side when i enter ".exit":
onetwothree