0
我正在使用TCP连接和node.js构建一个简单的聊天室。我期待在“Enter”之后发送文本,但发生的是每个字符在按下后立即发送。这是我的代码...在node.js中将数据从客户端传输到服务器
var server = net.createServer(function(conn){
console.log('\033[92m new connection! \033[39m');
conn.write('> welcome to \033[92mnode-chat\033[39m! \n'
+ '> ' + count + ' other people are connected at this time.'
+ '\n > please write your name and press enter: '
);
count ++;
conn.setEncoding('utf8');
conn.on('data', function(data){
console.log(data);
});
conn.on('close', function(){
count --;
});
});
能告诉你在客户端的代码? –
我使用Telnet作为我的客户端。 – Misaki