Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay... try and understand this. TCP Sockets isn't about transferring packets over the network (at least conceptually), its actually a stream of bytes which are transferred in the same sequence to be received on the other end, without fail.</p> <p>Now the lower layers (IP and so on), breaks the stream into packets and send it over the network. The TCP stack on the receiving end reassembles the packets (ask for retransmissions if necessary) and form a stream out of it again, as and when it keeps receiving the packets from lower layers. A <code>read()</code> socket call on the destination will fetch you the bytes that are received in the stream so far. Therefore, you can never be sure if a single <code>read()</code> call will fetch you all the data that was sent.</p> <p>The trick is to use multiple <code>read()</code> calls. You can have two possible scenarios to deal with this:</p> <p>(1) When you know how exactly many bytes you're supposed to receive. Here, you just keep on calling <code>read()</code> until you have received the said amount of bytes.</p> <p>(2) When you don't know how many bytes you're supposed to receive. This is rather tricky. Here you have to decide on a Sentinel. So, at the sending end, you send all the data that you have to send and then send this Sentinel. By the time I'm sure you must have understood it that at the receiving end, you keep on <code>read()</code>ing until you receive the Sentinel.</p> <p>Never think of TCP-Sockets as packets. Its easy to sink it in when you think of them as streams.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload