Hello, I am building a telnet server with node js.

Has anyone ever used the *readline* module with socket as input and output?

i.e. *readline.createInterface(socket, socket);*

It seems everything goes wrong when I use socket as I/O

Here is my code:

===============================================

/*
 * Callback method executed when a new TCP socket is opened.
 */
function newSocket(socket) {

//console.info(socket);
var option = {
input: socket,
output: socket,
terminal:true
};

var rl =readline.createInterface(option);

rl.write("Welcome to the Telnet server!\n");//Works fine
rl.setPrompt(">");
rl.prompt();

*rl.on('line', function (line){//On reading a line!*

* line = line.trim();*
* console.info("Read a line!")*

* if(line === "@quit") {*
* socket.write('Goodbye!\n');*
* closeSocket(socket);//The function is defined elsewhere*
* }else if (line === "enable") {*
* socket.write("Enter enable mode!\n")*
* rl.setPrompt("#");*
* }else{*
* socket.write('echo:'+line+'\n');*
* }*
* rl.prompt();*

* });*

};

// Create a new server and provide a callback for when a connection occurs
var server = net.createServer(newSocket);
server.listen(8888);

console.info('Server has started!');

============================================
After I telnet into the server and input 'abc', the results shown in the 
*client* are:

*Welcome to the Telnet server!*
*>abc  //Input abc*
*abc*
*>echo:abc*


*>echo:echo:abc*
============================================
And the *server* side:

*Server has started!*
*Read a line!*


*Read a line!*
============================================

It seems it reads twice after I send my input, how could this happen?

Any alternative for building a telnet server with completion function of 
NodeJS is also welcome.

*Thank you so much!*

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/ed8aaddc-be96-490a-ac5b-f63ce80a14bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to