2

Can someone tell me when does TCP send the data to the application layer (when receiving it) and if the message is divided into multiple segments does it wait till they all arrive to forward to application layer? what happens specifically , I tried searching online but I couldnt find an answer

  • Did any answer help you? if so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer. – Ron Maupin Aug 7 '17 at 22:12
1

The abstraction model for an application using TCP is a stream of bytes. Bytes will be delivered to the receiving application in the same order they were sent by the sending application but often not in the same sized chunks. If an application wants to send messages over a TCP connection it will need to provide it's own message framing.

If a packet is lost and needs to be retransmitted or if the network reorders packets then the receiving TCP implementation will need to hold the data after the gap back until it can deliver the data to the receiving appliation in order.

0

You should go to the source document, RFC 793, TRANSMISSION CONTROL PROTOCOL. Section 3.8, Interfaces describes this:

Receive

Format: RECEIVE (local connection name, buffer address, byte count) -> byte count, urgent flag, push flag

This command allocates a receiving buffer associated with the specified connection. If no OPEN precedes this command or the calling process is not authorized to use this connection, an error is returned.

In the simplest implementation, control would not return to the calling program until either the buffer was filled, or some error occurred, but this scheme is highly subject to deadlocks. A more sophisticated implementation would permit several RECEIVEs to be outstanding at once. These would be filled as segments arrive. This strategy permits increased throughput at the cost of a more elaborate scheme (possibly asynchronous) to notify the calling program that a PUSH has been seen or a buffer filled.

If enough data arrive to fill the buffer before a PUSH is seen, the PUSH flag will not be set in the response to the RECEIVE. The buffer will be filled with as much data as it can hold. If a PUSH is seen before the buffer is filled the buffer will be returned partially filled and PUSH indicated.

If there is urgent data the user will have been informed as soon as it arrived via a TCP-to-user signal. The receiving user should thus be in "urgent mode". If the URGENT flag is on, additional urgent data remains. If the URGENT flag is off, this call to RECEIVE has returned all the urgent data, and the user may now leave "urgent mode". Note that data following the urgent pointer (non-urgent data) cannot be delivered to the user in the same buffer with preceeding urgent data unless the boundary is clearly marked for the user.

To distinguish among several outstanding RECEIVEs and to take care of the case that a buffer is not completely filled, the return code is accompanied by both a buffer pointer and a byte count indicating the actual length of the data received.

Alternative implementations of RECEIVE might have the TCP allocate buffer storage, or the TCP might share a ring buffer with the user.

  • So if let's say the message was divided into 3 , and the middle one didn't arrive TCP would wait till it's re transmitted to send them all of send the 2 that arrived and then resend the one retransmitted ? @ron – Fred Gebrael Mar 25 '16 at 16:01
  • It's really up to the implementation on how to handle this sort of thing. You should study the RFC; I only quoted part of it, but you should really understand how TCP should work, and where all the implementation-specific parts are. Your question doesn't have a single overall answer: Windows, Unix, BSD, Linux, etc. could all have different, yet correct, implementations of this. – Ron Maupin Mar 25 '16 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.