If you drop packets, you will see a delay in transmission, because it must retransmit dropped packets. This can be very significant, although there is a TCP option called selective acknowledgment, which, if supported by both parties, will only re-send packets that have been deleted, and not every packet since the reset. There is no way to control this in your code. By default, you can always assume that every packet is delivered for TCP, and if there is some reason why it cannot deliver every packet in order, the connection will be reduced either by timeout or by one end of the connection sending RST.
What you see is most likely the result of the Nagle algorithm. What it does, instead of sending every bit of data as it is published, sends one byte, and then waits for confirmation from the other side. While it waits, it combines all the other data that you want to send, and combines them into one large packet and then sends. Since the maximum size for TCP is 65 thousand, it can combine quite a lot of data into one packet, although it is extremely unlikely that this will happen, in particular, since the default buffer size for winsock is about 10 thousand or so (I forgot the exact amount). In addition, if the maximum size of the receiver window is less than 65 thousand, it will send as much as the last allowed window size of the receiver. Window size also affects the Nagle algorithm, as well as how much data it can aggregate before it is sent, since it cannot send more than the window size.
The reason you see this is because on the Internet, unlike your network, the first ack needs more time to return, so the Naggle algorithm combines more of your data into one package. Locally, the return is effective instantly, so it allows you to send your data as fast as you can send them to the socket. You can disable the client-side Naggle algorithm using SetSockOpt (winsock) or Socket.SetSocketOption (.Net), but I highly recommend that you DO NOT disable Naggling on the socket if you are 100% sure that you know what you are doing. This is there for a very good reason.
Jeff tucker
source share