Title: Does an RST packet get sent to the application regardless of its sequence number?
Tags: c++;sockets;winapi;tcp;network-programming
Question: When an application is receiving data from a socket, it will receive the data in the correct order in which it was sent. TCP will know how to re-order the data based on the sequence number included in each packet's header.

But what about an ```RST``` packet, for example: if the other side sent some data and then sent an ```RST``` packet (by ungracefully closing the connection), and the ```RST``` packet was received before the data, what will happen in this case?

Will TCP wait for the data to be received and then give the application the data followed by the ```RST``` packet, or will TCP give the application the ```RST``` packet immediately before receiving the data?



Here is another answer: It doesn't make any difference. Receipt of the RST will cause the entire contents of the socket receive buffer to be thrown away in either case.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:03/17/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c++><sockets><winapi><tcp><network-programming>', 'Title': 'Does an RST packet get sent to the application regardless of its sequence number?', 'ViewCount': 86, 'id': 36051358, 'user_AboutMe': None, 'user_AccountId': None, 'user_DisplayName': None, 'user_Reputation': None, 'user_Views': None, 'user_id': None}}