1

I was playing around with Java sockets and telnet seemed like a good program to simulate a tcp client.

What i don't understand is why does telnet send data only on a enter? I am not looking for hacks to make it send the data immediately(as that is available ( Send data over telnet without pressing enter)) but i want to understand the internal working / design of telnet for which this seemed like the natural fit.

Community
  • 1
  • 1
Desert Ice
  • 4,461
  • 5
  • 31
  • 58
  • @KorayTugay, Somehow screwed up the link, fixed it now – Desert Ice Jan 28 '15 at 10:55
  • The fun part behind this question is rather than asking this you should actually go ahead and make a simple telnet clone which automatically transmits data and then try to use it. See what happens. I can make a prediction: you are going to feel quite a bit of frustration and possibly even cause problems that you need to manually repair, depending on what the result of the tranmission is going to be. – Gimby Jan 28 '15 at 11:00
  • I have the exactly opposite issue. I was trying a local chat application via telnet client. However each clients sends the message to server as soon as I type (i.e per letter). I want to send data only after enter. How can I achieve that ( on my Windows machine). – Saurabh Tiwari Aug 22 '19 at 10:12

3 Answers3

8

It's an implementation choice.

Basically, with both TCP and UDP you can buffer as much data as you want before sending it out. The target is to maximize payload size so you don't send a single packet for each key you type, something that you can easily achieve with a customized Java telnet client that flush()es a socket on each character.

Telnet was born as a remote shell client, and since a normal system shell processes text lines, implementors have found it reasonable to wait for the user to type ENTER before flushing the data to the server, which will stand by for carriage return if received a partial line

usr-local-ΕΨΗΕΛΩΝ
  • 26,101
  • 30
  • 154
  • 305
  • 3
    Isn't this completely different than the answer below? – Koray Tugay Apr 07 '15 at 15:20
  • This is half-wrong. By default telnet line-buffers data, only sending on Enter. However, you can configure it to send data as it is typed, and the telnet server (the thing you're connecting to) can also configure it to send data as it is typed. – Daniel Griscom Apr 11 '18 at 20:34
  • `windows(win10)` and `linux(ubuntu 18.04)` has different telnet default config. windows telnet default send echo char you type; ubuntu telnet defalut send line when type enter. – chengzi Nov 24 '21 at 07:09
3

I know this is an old thread, but I just wanted to add my findings. The Telnet program completely controls the way character by character or lines is sent. I tested this on a MAC, so I'm not sure for other platforms if you press ^] you can type "mode character" or "mode line" you can change this behavior.

  • thanks @inaki-zuloaga this is the part I was looking for. Now I'm reading about `option negotiation` in the RFC 854 :) – Ray Dec 19 '18 at 22:42
0

No, telnet does not send the buffer when you press Enter, it sends every single key you type. Otherwise vi and some other editors won’t work. What makes you believe this is that when you press enter you get a response from the host. For example you type ls –la and when press Enter you get a response, but telnet has sent all the keys one by one but you get the host response when you press Enter. Most of telnet emulators have theremote echo option set to true, which means the host echoes back all the keys you type. To test this type in more filename and press enter, it shows a page of information, and waits for a key, you may press Space: one more page, Enter: one more line, or Q to quit. There is a lot of information about telnet in Internet, look for RFC 854 Telnet Protocol Specification.

ja_mesa
  • 1,971
  • 1
  • 11
  • 7
  • 3
    Isn't this completely different than the answer above? – Koray Tugay Apr 07 '15 at 15:20
  • It is _usually_ possible in this day and age to negotiate sub-options so that character _can_ be sent as they are typed - however whether you _should_ is a significant issue! Remember, the remote end of the link could be somewhere around the other side of the world so the time to send the character and get the reply before echo-ing it on-screen (which is why, presumably you want to do it that way) can be long enough to be uncomfortable, and quite inefficient. In nearly all cases it is better to operate in the _native_ mode where a line of (typed) text is possibly edited and then sent whole... – SlySven Jun 07 '17 at 17:46
  • According to my tests this affirmation is wrong, i tested it using a command line telnet client on macOS and a socket server program in java, the server only received the messages after I pressed enter into the telnet client. – justcode Apr 04 '18 at 16:38
  • This is half-wrong. By default telnet line-buffers data, only sending on Enter. However, you can configure it to send data as it is typed, and the telnet server (the thing you're connecting to) can also configure it to send data as it is typed. – Daniel Griscom Apr 11 '18 at 20:33