CSecurity
asked on
Java inputstream never leaves
I'm coding a server app in Java.
I wrote data receive part in server like this:
String s;
in = new DataInputStream(client.get InputStrea m());
And below this code after some other processings...
while ((i = in.read()) != -1) {
s = s + (char) i;
}
System.out.println("OK! We received data part");
This code never prints out "OK! We received data part" till I close connection from client!
Why?
So how can I read data from inputStream?
Thanks from now!
I wrote data receive part in server like this:
String s;
in = new DataInputStream(client.get
And below this code after some other processings...
while ((i = in.read()) != -1) {
s = s + (char) i;
}
System.out.println("OK! We received data part");
This code never prints out "OK! We received data part" till I close connection from client!
Why?
So how can I read data from inputStream?
Thanks from now!
read is blocking call, will wait untill it receives data from client
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You should define boundry of the request and read till that point.
ASKER
b. you close the OutputStream of client
How? My client is coded in VB6.
And is there another call or reading method which can leave in inputstream?
How? My client is coded in VB6.
And is there another call or reading method which can leave in inputstream?
ASKER
P.S please tell me exit while code.... (in while how can I exit) in VB I write-> exit for. exit do or...
Thanks
Thanks
Not sure how you can close output fd in VB. If you are expecting data from the client in terms of line, you can use readLine() function
ASKER
how to exit while() loop? I should use return?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Assuming that from VB program, you are trying to send the commands line by line,
i would suggest to use the following:
String command = in.readLine();
// Work on the command
Do NOT read char by char
i would suggest to use the following:
String command = in.readLine();
// Work on the command
Do NOT read char by char
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.