Link to home
Start Free TrialLog in
Avatar of CSecurity
CSecurityFlag for Iran, Islamic Republic of

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.getInputStream());


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!
Avatar of Ajay-Singh
Ajay-Singh

read is blocking call, will wait untill it receives data from client
ASKER CERTIFIED SOLUTION
Avatar of Ajay-Singh
Ajay-Singh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You should define boundry of the request and read till that point.
Avatar of CSecurity

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?
P.S please tell me exit while code.... (in while how can I exit) in VB I write-> exit for. exit do or...

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
how to exit while() loop? I should use return?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial