Even setting ReadableStream.setEncoding('utf8'), node still can't show
Chinese or other chareacters.
===========server.js===============
var net = require('net');
var server = net.createServer();
var clients = [];
server.on('connection', function(socket){
console.log("got a new connection");
socket.id = parseInt(Math.random()*1000, 10);
clients.push(socket);
socket.on('data', function(data){
console.log('got data:', data.toString());
socket.setEncoding('utf8');
clients.forEach(function(otherSocket){
if(otherSocket !== socket) {
otherSocket.write(data);
}
});
})
});
server.on('error', function(err){
console.log('Server error: ', err.message);
});
server.on('close', function(){
console.log('Server closed');
var index = clients.indexOf(socket);
clients.splice(index, 1);
});
server.listen(4001);
=============client.js=================
var net = require('net');
var port = 4001;
var client;
process.stdin.resume();
(function connect(){
client = net.createConnection(port);
client.setEncoding('utf8');
client.on('connect', function(){
console.log("connected to server");
});
client.on('error', function(err){
console.log('Error in connection:', err);
});
client.on('close', function(){
console.log('connection got closed, will try to reconnect');
});
client.pipe(process.stdout, {end:false});
process.stdin.pipe(client);
}());
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.