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:
Can anyone please point me to what's the correct control sequence to backspace and remove the character from the screen?
Thanks,
Tom
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With