2

I have created a simple telnet server using QTcpSocket. It works great when the (telnet) client sends a command one line at a time.

I would now like my telnet server to trap the up/down arrow keys so that I can recall previous commands from the client. When I press up/down on the keyboard at the telnet client I see the ^[[A onscreen but I don't think it is sent to the server.

Is there a way to force the telnet client to send these characters (without needing to press enter)? I suspect that this has to do with unbuffered mode, but the docs say QTcpSocket cannot do unbuffered mode. Am I on the right track? Is there a way to do this?

TSG
  • 4,242
  • 9
  • 61
  • 121

2 Answers2

3

The solution seems to be that the telnet server must tell the client to go into character mode. This can be done by sending IAC control sequences. An example is here:

Forcing telnet client into character mode

Community
  • 1
  • 1
TSG
  • 4,242
  • 9
  • 61
  • 121
0

You told that you programmed a telnet server using QTcpSocket and you said nothing about the telnet client... is a commercial telnet client? have you programmed it on your own?

If your question is

"how can I force the telnet client to send these characters (without needing to press enter)"

then you have to tell us about the telnet client... otherwise how can we help you? If you use the Linux command-line telnet client then I think you should read about LINEMODE (surfing the web you can fine details about it quite easily).

The documentation of QTcpSocket tells that you can't open it in QIODevice::Unbuffered mode, but this does not imply that you won't be able to send/receive single characters...

Morix Dev
  • 2,700
  • 1
  • 28
  • 49
  • My Telnet server app should work for all telnet clients, and assume they support xterm/vt100/ansi codes etc. I don't want to program for a single telnet client. – TSG Sep 23 '14 at 13:42
  • @GenerationDSystems: you're right and it was exactly what I've meant: if your question is "how can I force the telnet client to do something" then my answer is "it depends on which telnet client you are using"... I am pretty sure that the buffering does not occur on `QTcpSocket` which is listening for receiving some data... so server-side you should be ok... anyway you haven't shared with us your code, so I do not know what you are doing and so I am just guessing... – Morix Dev Sep 23 '14 at 13:46
  • I don't have relevant code to share. My question is more generic. Do I handle this by looking for codes on the input stream? Do telnet clients work in "LINEMODE" by default? not sure how to approach the problem – TSG Sep 23 '14 at 14:10
  • @GenerationDSystems: I think that the majority of telnet clients work in `LINEMODE`... so I do not think that you can look on codes on input stream for handling that, but I am not a real expert about telnet... so maybe someone else can provide you other details... – Morix Dev Sep 23 '14 at 14:29
  • The solution seems to be the server can tell the client (regardless of which telnet client) to go to character mode (not linemode) using IAC control sequences. – TSG Sep 24 '14 at 03:43
  • @GenerationDSystems: very good... I wasn't aware of that... I am always happy to learn something new! :) – Morix Dev Sep 24 '14 at 05:27