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