How the reading from and writing to sockets are synchronized?

Posted by Roman on Stack Overflow See other posts from Stack Overflow or by Roman
Published on 2010-03-22T15:36:13Z Indexed on 2010/03/22 15:41 UTC
Read the original article Hit count: 211

Filed under:
|
|
|

We create a socket. On one side of the socket we have a "server" and on another side there is a "client". Both, the server and client, can write to and read from the socket. It is what i understand. I do not understand the following things:

  1. If a server reads from the socket, does it see in the socket only those stuff which was written to the socket by the client? I mean if server writes something to the socket and than reads from the socket, will it (server) see in the socket the stuff it (server) wrote there? I hope not.

  2. Let's consider the following situation. A client write something to the socket and then it writes something new to the socket and then server reads from the socket. What will the server see there? Only the "new" stuff written by the client or both "new" and "old" one?

  3. If a client (or server) writes to the socket, can it see if the written information was received by other side? For example out.println("Hello, Server!") will return true it server received this message.

© Stack Overflow or respective owner

Related posts about java

Related posts about sockets