How can I read only one character at a time?

Answer Posted / chaitanya

This question is usually asked by people who are testing their server with telnet, and want it to process their keystrokes one character at a time. The correct technique is to use a psuedo terminal (pty). More on that in a minute.

You can have your server send a sequence of control characters: 0xff 0xfb 0x01 0xff 0xfb 0x03 0xff 0xfd 0x0f3, which translates to IAC WILL ECHO IAC WILL SUPPRESS-GO-AHEAD IAC DO SUPPRESS-GO-AHEAD. For more information on what this means, check out std8, std28 and std29. Roger also gave the following tips:

o This code will suppress echo, so you'll have to send the characters the user types back to the client if you want the user to see them.

o Carriage returns will be followed by a null character, so you'll have to expect them.

o If you get a 0xff, it will be followed by two more characters. These are telnet escapes.

Use of a pty would also be the correct way to execute a child process and pass the i/o to a socket.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is there any advantage to handling the signal, rather than just ignoring it and checking for the EPIPE error? Are there any useful parameters passed to the signal catching function?

1041


What exactly is a socket?

526


What's the difference between a socket and a port?

458


What is af_inet in socket?

477


What is difference between socket () and serversocket () class?

495






What is a socket file?

512


Why does it take so long to detect that the peer died?

1150


Where is the socket located?

476


What is socket programming in java?

492


Why do we need socket programming?

500


What is a sae socket?

516


How can I tell when a socket is closed on the other end?

975


How many sockets can a cpu have?

501


What's the difference between impact sockets and regular sockets?

476


What is the purpose of socket?

503