• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

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!
0
Valeri
Asked:
Valeri
1 Solution
 
objectsCommented:
Try flushing the output stream that is sending, and make sure it sends an end of line.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now