4

I have a server which opens a connections for a telnet client, like for example: I run the server ./server and in another window I run telnet client as telnet localhost 9999, as I run the telnet client, I will get new CLI prompt as CLI>>.

From this prompt I need custom tab completion, but many of the blog says we can really dont have readline feature implemented on the telnet side, if so we have go for our own client.

How do I achieve it? Any related help would be greatly appreciated. I am using linux(Ubuntu) and C language.

Haris
  • 12,120
  • 6
  • 43
  • 70
Puneeth
  • 419
  • 1
  • 6
  • 18
  • It seems you might want to [read more about the telnet protocol](http://en.wikipedia.org/wiki/Telnet). Especially the [related RFCs](http://en.wikipedia.org/wiki/Telnet#Related_RFCs) (like the one for [the linemode option](http://tools.ietf.org/html/rfc1184)). – Some programmer dude Dec 09 '13 at 14:13

3 Answers3

2

You have to put the telnet client in char mode, so it sends each key directly to the server when it's typed (instead of waiting for the return key to send a complete line). Then, whenever you receive a '\t', check what you received before that '\t', and depending on whether you can complete the line, send back the complete line or a list of possibilities. Basically, you're implementing readline() in the server.

Guntram Blohm
  • 9,667
  • 2
  • 24
  • 31
  • Can you tell me how to do this line mode to character mode ...is it programming or manual. – Puneeth Dec 09 '13 at 10:49
  • Check this: http://stackoverflow.com/questions/273261/force-telnet-client-into-character-mode – Guntram Blohm Dec 09 '13 at 10:51
  • This link I saw earlier, but not getting what to do exactly, I am novice to telnet. Do I need to enable character mode but how...is it while issuing the telnet command ..as telnet localhost 999 ..or it is something to do with programming ...or what should I type and where should I issue command. – Puneeth Dec 09 '13 at 11:13
  • Guntram really I need your help now... how can I receive single character from telnet client...recv will receive entire command? – Puneeth Dec 09 '13 at 12:53
1

You can implement this either on the client or on the server.

For the client-side implementation there are two ways (which are basically the same):

  1. When the client connects, the server sends a list of commands and their arguments, and that is cached in the client. When a user presses the TAB key the client searches this cached data.

  2. When the client notices the TAB key being pressed, it asks the server for a list of possible completions. For speed this list should be cached on the client side.

So the basic solution here is: Server sends data to client, client shows data.


For a server-side implementation, you have to use telnet negotiation to tell the client to send raw uncooked characters and keys without any interference to the server. Then the server can check for the TAB key and perform completion.

The problem here is that then you have to add all command line editing and prompting in the server code, and can't rely on the client be anything but a "dumb terminal".


Having all processing done server-side has the upside that you can use almost any telnet client (as long as it can handle the telnet negotiations) and don't have to make your own custom client. The drawback is that you then have to implement the whole command-line editing features yourself in the server, and that the latencies for key-presses can be high as each key has to be sent to the server and then echoed back from the server.

Having a custom client has the upside that there are libraries which can easily handle command-line editing and help with the completion. The major downside here is that you have to make a custom client.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Joachim I wanted to know how to receive the '\t'in the client...big problem here is how to collect character by character after setting telnet to CHARACTER mode.. – Puneeth Dec 09 '13 at 12:55
  • @Puneeth If you use a standard telnet client, and it's in character mode, then it should simply send the tab to the server as soon as it receives it. If you have a custom client, then e.g. the [GNU readline library](http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html) have support for the tab (or other character, it's configurable) to call a callback-function in your code. Read about [custom completers here](http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC44). – Some programmer dude Dec 09 '13 at 14:10
  • @Puneeth If you have a custom GUI-based client, then the GUI will have functionality to recognize keys, including tab. See the reference for the GUI toolkit you use in that case. – Some programmer dude Dec 09 '13 at 14:12
  • After setting telnet to character mode it started behaving weirdly, like it start processing every character and says invalid command(server code) – Puneeth Dec 10 '13 at 07:05
1

After you telnet host, input ctrl + ] to go into telnet command prompt, then execute mode character. After that, the telnet client goes into "character at a time" mode, and tab completion should work fine.

sunnogo@a3e420:~$ telnet 192.168.193.88 10015   
Trying 192.168.193.88...  
Connected to 192.168.193.88.  
Escape character is '^]'.  



my_prompt>
my_prompt>

my_prompt>

my_prompt>^]  
telnet> mod character

my_prompt��  
my_prompt>  
my_prompt>  
jeromesun14
  • 111
  • 1
  • 6