Home > OS >  How to read each char sent by Putty at Java server?
How to read each char sent by Putty at Java server?

Time:05-07

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 ?

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