'Chat app with Node.JS in Fedora Linux (in MobaXTerm). Server.js & Client.js are connected but messaging failed
I want to create a terminal chat application in Node.JS. I use MobaXTerm (WSL-Fedora). The problem is that the server and client can connect to each other, but I can't send a message from one side to the other.
Can somebody help me?
Thanks in advance!
//client.js
const net = require('net');
const client = net.createConnection({ port: 8124 }, () => {
// 'connect' listener.
console.log('connected to server!');
client.write('world!\r\n');
});
client.on('end', () => {
console.log('disconnected from server');
});
process.stdin.setEncoding('utf8');
process.stdin.on('readable',
function() {
var chunk = process.stdin.read();
if (chunk !== null) {
process.stdout.write(chunk);
}
}
);
//server.js
const net = require('net');
const server = net.createServer((c) => {
// 'connection' listener.
console.log('client connected');
c.on('end', () => {
console.log('client disconnected');
});
c.write('hello\r\n');
c.pipe(c);
});
server.on('error', (err) => {
throw err;
});
server.listen(8124, () => {
console.log('server bound');
});
process.stdin.setEncoding('utf8');
process.stdin.on('readable',
function() {
var chunk = process.stdin.read();
if (chunk !== null) {
process.stdout.write(chunk);
}
}
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
