title: WinSock error #10055
body: <p>I have client-server architecture build in python, unfortunately the original design was made that each request to server is represented by one TCP connection and I have to send requests in large groups (20 000+) and sometimes there occurs socket error <a href="http://support.ipswitch.com/kb/WSK-19980714-EM18.htm" rel="nofollow"><code>#10055</code></a>.</p>
  
  <p>I've already found out how to handle it in python:</p>
  
  <pre><code>&gt;&gt;&gt; errno.errorcode[10055]
  'WSAENOBUFS'
  &gt;&gt;&gt; errno.WSAENOBUFS
  10055
  </code></pre>
  
  <p>And build a code that is able to handle that error and reconnect (of course with little time delay to give server time to do whatever it has to do):</p>
  
  <pre><code>class MyConnect:
      # __init__ and send are not important here
  
      def __enter__(self):
          self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  
          # Try several reconnects
          for i in range(0,100):
              try:
                  self.sock.connect((self.address, self.port))
                  break
  
              except socket.error as e:
                  if e.errno == errno.WSAENOBUFS:
                      time.sleep(1)
                  else:
                      raise
  
          return self
  
      def __exit__(self, type, value, traceback):
          self.sock.close()
  
  # Pseudocode
  for i in range(0,20000):
      with MyConnect(ip,port) as c:
          c.send(i)
  </code></pre>
  
  <p>My questions are:</p>
  
  <ul>
  <li>is there any "<em>good practice</em>" way to do this?</li>
  <li>is <code>e.errno == errno.WSAENOBUFS</code> multi-platform? If not so, how to make it multi-platform?</li>
  </ul>
  
  <p><sub><strong>Note</strong>: I've tested in just on Windows yet, I need it to work on Linux too.</sub></p>