title: C#: How to deal with out-of-order TCP packets?
body: <p>Can please someone one explain how to deal with out-of-order packets. I'm using raw socket to capture packets, and parse them as they come, but some of them come in wrong order, for  example:</p>
  
  <ol>
  <li>Id...........Flags</li>
  <li>16390 : (PSH, ACK)  </li>
  <li>16535 : (PSH, ACK)</li>
  <li>16638 : (ACK)</li>
  <li>16640 : (PSH, ACK)</li>
  <li>16639 : (ACK)</li>
  <li>16695 : (PSH, ACK)</li>
  </ol>
  
  <p>Packets with IDs: 16390, 16535, 16695 are separate packets and can be processed freely
  Packets with IDs: 16638, 16640, 16639 are a sequence of packets and should be put in  ascending order before parsing. </p>
  
  <p>To make it worse packets with Push flag sometimes come first so I just pass them along to parser, and then packet that preceds it comes and parser just discards it as corrupted.</p>
  
  <p>Is there any way to deal with it?</p>