开发者

Telnet server -> backspace/delete not working

开发者 https://www.devze.com 2022-12-11 05:51 出处:网络
I\'m implementing a simple proof of concept Telnet server in C# and telnet to it via the windows built in telnet client.

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


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.


I just connected to a Cisco switch and traced how IOS is implementing it. IOS is sending 'BS' 'SPACE' 'BS' on an incoming 'BS' from the client. So, that's how I implemented it now and works great.


static uint8_t space = 0x20;
static uint8_t BS = 0x08;

if (ui8Char == 0x08)
{
if (i != 0) i--;
tcp_write(pState->pConnectPCB, &BS, 1, 1); 
tcp_write(pState->pConnectPCB, &space, 1, 1); 

Its delete the data which you echo on your terminal and also in your buffer. first check for backspace and decrement your buffer and then use BS and Space. Its work perfectly for Telnet. You donot have to change anything in teraterm or putty.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号