I've recently started messing around with Java sockets and telnet...
I want the user to be able to connect to the server, just type a letter and have it sent to the server, without pressing enter to send it. I'm sure there's no way for the server to set this up, but maybe telnet has a parameter or something which could allow this?
Maybe if I got the user to type stty cbreak
or stty raw
before running telnet, this would work? (UNIX only, I know!)
If I can get telnet to do this then it saves me having to write a special client just for this feature...
There actually is a way for the server to request this: It's called telnet option negotiation. Typically telnet
will default to configure the local tty in "raw" mode when you use port 23 and "cooked" (or "line") mode on other ports. Line mode is where you have minimalistic local editing and the data is sent when you hit return.
Once you disable linemode you can separately configure things like local echo.
EDIT: I think a reasonable sequence would be:
255, 253, 34, /* IAC DO LINEMODE */
255, 250, 34, 1, 0, 255, 240 /* IAC SB LINEMODE MODE 0 IAC SE */
255, 251, 1 /* IAC WILL ECHO */
That enables TELOPT_LINEMODE
(34) and then sets the linemode LM_MODE
to 0
(which I think is the right way to tell the client not do to any local editing). Finally it says WILL ECHO
indicating the server will echo (so the client will not).
The client (if it supports telnet negotiation) will reply with sequences like IAC blah blah
or "quoted" sequences like IAC SB ... IAC SE
which you can detect and filter out of your input stream.