有人可以告诉我如何设置linemode到telnet测试?我google了很多,但不幸的是我没有成功。 我有这个超级简单的代码
var net = require('net');
var server = net.createServer(function(c) {
console.log('socket opened');
c.setEncoding('utf8');
c.on('end', function() {
console.log('connection/socket closed');
});
c.on('data', function(data) {
console.log('Data:'+data);
c.write('Answer:'+data);
// c.end(); // close socket/conection
});
});
server.listen(8124, function() { // start server (port 8124)
console.log('server started');
});
但是测试看起来像这样:
客户端:
Microsoft Telnet> open localhost 8124
Answer:dAnswer:daAnswer:atAnswer:taAnswer:a
服务器
C:\Users\Laura\node server.js
server started
socket opened
Data:d
Data:a
Data:t
Data:a
答案 0 :(得分:0)
您希望获得如下所示的telnet输入
Answer: a
Answer: b
Answer: c
然后您需要将\r is carriage return
与line feed (\n)
一起发送。所以你的代码应该像下面那样
var server = net.createServer(function(c) {
console.log('socket opened');
c.setEncoding('utf8');
c.on('end', function() {
console.log('connection/socket closed');
});
c.on('data', function(data) {
console.log('Data:'+data);
c.write('\r\nAnswer:');
// c.end(); // close socket/conection
});
});