Is there a way to immediately print the message received from the client without using an infinite loop to check whether the input stream is empty or not?
Because I found that using infinite loop consumes a lot of system resources, which makes the program running so slow. And we also have to do the same (infinite loop) on the client side to print the message on the screen in real time.
I’m using Java.
Is there a way to immediately print the message received from the client without
Share
You should be dealing with the input stream in a separate Thread – and let it block waiting for input. It will not use any resources while it blocks. If you’re seeing excessive resource usage while doing this sort of thing, you’re doing it wrong.