Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The side that is that one that initiated the closing of the connection is the one that ends up in the <code>TIME_WAIT</code> state. <code>read()</code> returning 0 is supposed to indicate that the server closed the socket first, so yes - this should mean that the <code>TIME_WAIT</code> ends up on the server side, and the client goes through <code>LAST_ACK</code>.</p> <p>At the end of the day, you can't avoid a <code>TIME_WAIT</code> state. Even if you succeed in moving it from the client to the server side, you still can't re-use that <code>(server host, server port, client host, client port)</code> tuple until the <code>TIME_WAIT</code> is over (regardless of which side it's on).</p> <p>Since three parts of that tuple are fixed in your scenario (<code>server host</code>, <code>server port</code>, <code>client host</code>), you really only have these options:</p> <ul> <li><p>Try to make more client ports available. Some operating systems only use a small range of the available ports for "ephemeral ports" by default (I'm not sure about OSX in this regard). If that's the case, see if you can change the range with a configuration tweak in the OS, or alternatively have the application hunt for a working port with <code>bind()</code>/<code>connect()</code> in a loop until the connection works.</p></li> <li><p>Expand the number of <code>client host</code> values available, by using multiple IP addresses on your client. You'll have to have the application <code>bind()</code> to one of these IP addresses specifically though.</p></li> <li><p>Expand the number of <code>server host</code>/<code>server port</code> values available, by using multiple ports and/or IP addresses on the server. The client will need to pick one to connect to (round robin, random, etc).</p></li> <li><p>Probably the best option, if it's doable: refactor your protocol so that connections that are finished aren't closed, but go into an "idle" state so they can be re-used later, instead of opening up a new connection (like HTTP keep-alive).</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload