Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telnet server -> backspace/delete not working

I'm implementing a simple proof of concept Telnet server in C# and telnet to it via the windows built in telnet client. I echo all non IAC data back to the client. However, I can't figure out how to get backspace/delete to work correctly. I tried several combinations acting on 'BS' from the telnet client:

  • 'BS' (moves cursor back by one but doesn't delete character)
  • 'BS''DEL' (same result as 'BS' only)
  • 'BS''DEL''ESC[3~' (same result)

Can anyone please point me to what's the correct control sequence to backspace and remove the character from the screen?

Thanks,

Tom

like image 830
TJF Avatar asked Mar 27 '26 08:03

TJF


2 Answers

I was stuck trying to figure this out for ages but its actually extremely simple if echo is on. When a \b (backspace) is detected. You can send (through socket):

Socket.Send(new byte[] { 0x08, 0x20, 0x08 });

0x08 sends the backspace, which is a non destructive backspace at it just moves the cursor to the left one. 0x20 sends a space which the deletes that character, and then the backspace again moving the cursor back to the left. Works like a charm!

Cheers

like image 162
Mastermosley Avatar answered Mar 29 '26 22:03

Mastermosley


Behavior of delete and backspace are dependent on the terminal emulation of the server. Further, hitting backspace and or delete in the client may or may not send the actual backspace and delete keycodes to the server, depending on what it believes the emulation to be. I don't believe there is a terminal agnostic command for moving back one character and removing the last character. Here's a good discussion of the problem.

Finally, don't use the windows built in telnet client. It sucks. I prefer Van Dyke's SecureCRT, but if you don't want to spend money, PuTTY is a popular free client.

like image 20
Jherico Avatar answered Mar 29 '26 20:03

Jherico



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!