title: Bind error while recreating socket
body: <p>A have the following listener socket:</p>
  
  <pre><code>int sd = socket(PF_INET, SOCK_STREAM, 0);
  
  struct sockaddr_in addr;
  bzero(&amp;addr, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_port = htons(http_port);
  addr.sin_addr.s_addr = INADDR_ANY;
  
  if(bind(sd,(sockaddr*)&amp;addr,sizeof(addr))!=0)
  {
      ...
  }
  
  if (listen(sd, 16)!=0)
  {
      ...
  }
  
  int sent = 0;
  for(;;) {
      int client = accept(sd, (sockaddr*)&amp;addr, (socklen_t*)&amp;size);
      if (client &gt; 0)
      {
          ...
          close(client);
      }
  }
  </code></pre>
  
  <p>If a use</p>
  
  <pre><code>close(sd);
  </code></pre>
  
  <p>and then trying to recreate socket with the same code, a bind error happens, and only after 30-60 second a new socket is created successfully.</p>
  
  <p>It there a way to create or close in some cool way to avoid bind error?</p>