Home > front end >  How to read each char sent by Putty at Java server ? (and how to force "Local line editing"
How to read each char sent by Putty at Java server ? (and how to force "Local line editing"

Time:05-03

After forcing off the "Local line editing" at Putty (Raw mode), all chars typed are sent to the server without the Enter (checked it with Wireshark).

I have this code:

ServerSocket listener = null;
BufferedReader is;
listener = new ServerSocket(22);
socket = listener.accept();

is = new BufferedReader(new InputStreamReader(socket.getInputStream()););
while (true) {
    line = is.readLine();
    os.write("Shell#");
    os.flush(); 
}

This code need an Enter from Putty to read all the sequence chars typed,

How to read these sent chars one by one at Java Server side ?

Additionnaly, how to force at off the Putty "Local line editing", from the Java Server ? (Default option at Putty is at Auto)

CodePudding user response:

As you have discovered, readLine() reads whole lines, thus won't return before a newline marks the end of a line.

Also note that the whole point of a BufferedReader is to buffer data.

The real answer here is to carefully look at the different classes your code is using. Meaning: check out read() in the InputStreamReader class!

  • Related