Search code examples
javasocketschatinputstreamtelnet

How to fix backspaces sent via Telnet to Inputstream in Java?


On my Java Chatserver users can change their username by using backspaces infront of their message.

I am currently coding a chat-server and client in Java. It works really well but I have the annoying 'bug', that the users can send messages without their username by using backspaces infront of their messages because telnet or the used BufferedReader-InputStream is saving backspaces in the message-string.

I tried to replace backspaces which made it impossible for users to change spelling mistakes.

I don't know what I should try next.

Example: Test>[10 backspaces]This is a test. The others are getting the message This is a test. but the actual message should be Test:This is a test.


Solution

  • This line of code fixed my issue partly:

    while (input.contains("\b")) input = input.replaceAll("^\b+|[^\b]\b", "");