Here the scenario I'm imagining. Two messages are transferred, both will require 2 packets each (I know you don't deal with packets directly with TCP, but on the IP level each message will consist of 2 packets [or segments as they're called in TCP])

The problem I'm imaging is buffering the first packet of the first message, but a router dumps the second packet for some reason. Being TCP, the second packet is guaranteed to be resent, and I know that TCP will hand these two packets up to the application layer in order. But while being handled asynchronously, this first packet will still be handed up to the application which will not block during the period in which the underlying TCP layer handles the retransmission of the second packet. What will happen if the first packet of the second transmission arrives before the last packet of the first transmission? Will TCP not hand these packets up until the first transmission is handled in full? Will an async client not send the second message before the first has been handled in full?

I know that TCP will guarantee the order of packets for each message. My confusion is whether it will fully complete one transmission before processing the second transmission when being handled asynchronously.

1 Answer 1


TCP is a stream protocol (not packets as you clearly said). The TCP stack layer will only deliver the data in stream order. Async or not, the data will not be handed to the client out of order.

TCP would not be a very good streaming protocol if it did deliver data out of order. That's kind of the point of the protocol. :-)

  • Yes, and no. TCP is built on the IP network stack, and the IP protocol sends all data in IP packets including TCP segments. Packets/segments will not necessarily arrive in order, but will not be handed up to the application layer out of order. But each segment is part of a single transmission, and I'm talking about two transmissions. For example, if you send a 1 gig file asynchronously and than send another 1 gig file, the first file will obviously not be completed before the second send call is made. Will the second file not be sent (at all) until the first file has been fully transferred?
    – Jason
    Feb 9, 2014 at 5:03
  • I know that the second transmission will likely be delayed because the nature of TCP is to guarantee order, but I have never heard (just as a matter of fact) how large file are handled on async systems of if there is specific concerns or steps that need to be taken.
    – Jason
    Feb 9, 2014 at 5:11
  • @Jason I think you may find this StackOverflow question and this one to be of interest. I think your large files are going to run into the case where they're filling the outbound network buffers at the OS level before some of the issues you're talking about will start to crop up.
    – J Trana
    Feb 9, 2014 at 5:27
  • @Jason, your question is not clear that it is discussing two independent connections. You used the terminology, messages. TCP does not have messages. Messages would be some other higher level protocol on top of the stream. If the messages are on the same connection, then I would expect the transmissions to be made serially. If the connections are independent on different sockets then they can be made in parallel.
    – Bill Door
    Feb 9, 2014 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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