Link to home
Start Free TrialLog in
Avatar of Valeri
ValeriFlag for Bulgaria

asked on

Response in same Socket

Hi all,
I have written a simple socket server. Through this socket I'm sending information to another machine and I'm waiting for response in the same socket.
I can not receive response because the BufferedReader is not ready!
I'm waiting for the response in this way :

try {
BufferedReader inFrom = new BufferedReader(new InputStreamReader(clientSocket.getInputStream(), "UTF-8"));
if (!inFrom.ready()) System.out.println("The buffer is still not ready!!!");
String str;
 while ((str = inFrom.readLine()) != null) {
    System.out.println(str);
 }
} catch (Exception e) { e.printStackTrace(); }

I tried to put this code ahead the code written above:
while (inFrom.ready()) {
  Thread.sleep(100);
}
and then the BufferedReader becomes ready, but I still can not receive any information, even that the information is sent from the other machine!
Do you know how can I receive response into the same socket. Probably I'm doing something wrong?!
Thanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia 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