2013-03-02 64 views
0

有人能告訴我如何將linemode設置爲telnet測試嗎?我搜索了很多,但不幸的是我沒有成功。 我有這樣的超級簡單的代碼使用telnet的Node.js測試服務器 - 設置Linemode

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

要G等類似如下

Answer: a 
Answer: b 
Answer: c 

遠程登錄輸入,那麼你需要兩個\r is carriage returnline 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 
    }); 
});