I am creating a socket server for a school project. The client is written in C# so the ObjectInputStream object I have been using so far is not working.
I am now trying to use InputStreamReader. In this example, the while (true) loop is running at full throttle all the time. Using the ObjectInputStream it'd wait for an object to arrive.
How can I do this in a proper way?
private InputStreamReader inputStream;
@Override
public void run() {
while (true) {
try {
// ObjectInputStream.read() waits for an object to arrive,
// so the execution is paused here
int data;
String string = new String();
while ( (data = inputStream.read() ) != -1) {
char thisChar = (char) data;
string = string + thisChar;
}
} catch (IOException ex) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
break;
}
}
}
Reader