jakeisstoked
Technical User
Ok, I have this really simple function in some client / server programs, I am trying to read an input stream, it sends ok, says I send something like
"ostream.write("message".getBytes());" on a client
and it sends. And this little procedure reads the stream;
private void processRequest(){
String request = new String();
int Byte;
while(true){
try{
inStream = socket.getInputStream();
while((Byte = inStream.read()) >= 0){
request = request + (char)Byte;
}
System.out.println(request);
}
catch(Exception e){
e.printStackTrace();
}
}
}
Ok the first while is supposed to be infinite,
but I want to get one "message" at a time, but still read byte by byte. I can recieve the stream byte by byte, but I can't figure out how to terminate the second while loop, it just stays in it reading bytes forever (and when it gets to the end of the input stream it just sits there, it never gets to "System.out.println(request);").
Any clues? I know this is really simple, any tips would be much appreciated.
-Jake
"ostream.write("message".getBytes());" on a client
and it sends. And this little procedure reads the stream;
private void processRequest(){
String request = new String();
int Byte;
while(true){
try{
inStream = socket.getInputStream();
while((Byte = inStream.read()) >= 0){
request = request + (char)Byte;
}
System.out.println(request);
}
catch(Exception e){
e.printStackTrace();
}
}
}
Ok the first while is supposed to be infinite,
but I want to get one "message" at a time, but still read byte by byte. I can recieve the stream byte by byte, but I can't figure out how to terminate the second while loop, it just stays in it reading bytes forever (and when it gets to the end of the input stream it just sits there, it never gets to "System.out.println(request);").
Any clues? I know this is really simple, any tips would be much appreciated.
-Jake