This discussion is archived
1 Reply Latest reply: Feb 24, 2012 12:43 AM by EJP RSS

How does READ work on Sockets

898032 Newbie
Currently Being Moderated
My question might be silly.. but i am just not able to get hang of it.

Suppose i have a Client Server configuration in my application and i have written Server code in such a way that it reads the first request from the Client, starts processing and then waits for something more from the client. To illustrate consider the below snippet.

P.S: Ignore the try-catches

Socket skt = new Socket(...);
DataInputStream dIn = ...;
DataOutputStream dOut = ...;

dOut.writeUTF("ContactMe");

String reply = dIn.readUTF(); //Blocking Call??

//Starts processing, and client writes something more in the socket and here processing is still not done.

String more = dIn.readUTF(); //Will this read the extra things that the client wrote in the socket even though this line was not executed before the client started writing the extra things in the socket??!!!!!


PEACE,
Sandeep
  • 1. Re: How does READ work on Sockets
    EJP Guru
    Currently Being Moderated
    String reply = dIn.readUTF(); //Blocking Call??
    Yes that is a blocking call.
    String more = dIn.readUTF(); //Will this read the extra things that the client wrote in the socket even though this line was not executed before the client started writing the extra things in the socket??!!!!!
    Yes.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points