views:

674

answers:

2

I have a Solaris daemon written in Java6. Clients can connect to it using a telnet style interface. They telnet to a particular port, and I read lines of input and act on them.

At one point in I need to prompt the user to enter a password, and while they're entering that I want to disable the echoing of characters back to the telnet client.

The code has a Socket object and creates an InputStream from the socket's getInputStream() result, then reads and buffers characters from the InputStream, breaking them up on cr/lf boundaries.

I can't see any attributes on either the InputStream or the Socket to disable the echoing of characters back to the client.

Can someone nudge me in the right direction?

+4  A: 

Sounds like you need to build a simple Network Virtual Terminal that supports the no echo etc commands. There is already a good answer you should refer to on SO : http://stackoverflow.com/questions/267538/telnet-server

ChrisGNZ
You're spot on, Chris. The RFC clears up a lot. I was taking a very simplified view of telnet; implementing it as a proper NVT should accomplish what I want. Thanks.
Andrew
+2  A: 

You should understand where the echo is coming from. TCP connections and java InputStreams don't provide echo on their own. The telnet program that the user runs normally starts in "local echo" mode, meaning that it echoes everything typed by the user to the user's screen. When the telnet client connects to an actual telnet server, it commonly negotiates "remote echo" mode in which case the remote system provides the echo. When telnet connects to something else, like an HTTP or SMTP server, it just stays in local echo mode.

The user can issue a command to turn off local echo in the client, but it wouldn't be very user-friendly to require your users to do that. As the other answer says, if you want to switch echoing on and off, you will need to enhance your server to support the telnet protocol, then negotiate remote echo with clients.

If you do this, you'll also encounter the issue of line-at-a-time vs. character-at-a-time. Telnet starts in line-at-a-time mode. It honors line-editing keys like backspace locally, and only sends the line to the server when the user hits return. If you're doing remote echo, then you need to echo characters as the user types them, not after he hits return. So you'll have to support character-at-a-time and implement line editing in the server.

You should look closely at the telnet server program on your server host. It might be possible to use the existing telnet server as a frontend for your program, rather than reimplementing everything that it does. Good luck.

Kenster