I've been trying to do communication from another language to Java, but when I try read data from DataInputStream in a while loop...
static String getData(DataInputStream stream){
int charbyte;
StringBuilder strbuilder = new StringBuilder();
try {
while ((charbyte = stream.read()) != -1){
strbuilder.append(Character.toChars(charbyte));
}
stream.close();
return new String(strbuilder);
} catch (Exception e) {
return null;
}
}
The problem is stream.read() is not returning -1 because it just keeps waiting for new data to be sent. How can I just get the data that was just sent?