Response in same Socket

Posted on 2005-05-16
Last Modified: 2010-03-31
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) {
} catch (Exception e) { e.printStackTrace(); }

I tried to put this code ahead the code written above:
while (inFrom.ready()) {
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!
Question by:Valeri
    1 Comment
    LVL 92

    Accepted Solution

    Try flushing the output stream that is sending, and make sure it sends an end of line.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now