title: Python Socket [Errno 10049] 'The requested address is not valid in its context'
body: <p>I'm trying to get a python socket code to work. The server is running fine, but the client won't bind to an IP address. Here's the error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "chatClient.py", line 27, in &lt;module&gt;
      s.bind((host, port))
    File "C:\Panda3D-1.8.1\python\lib\socket.py", line 224, in meth
      return getattr(self._sock,name)(*args)
  socket.error: [Errno 10049] The requested address is not valid in its context
  Press any key to continue . . .
  </code></pre>
  
  <p>And here's the code...</p>
  
  <pre><code>import socket
  import threading
  import os
  import time
  
  tLock = threading.Lock()
  shutdown = False
  
  def receving(name, sock):
      while not shutdown:
          try:
              tLock.acquire()
              while True:
                  data, addr = sock.recvfrom(1024)
                  print str(data)
          except:
              pass
          finally:
              tLock.release()
  
  host = '76.106.199.228'
  port = 0
  
  server = ('76.106.199.228', 5000)
  
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.bind((host, port))
  s.setblocking(0)
  
  rT = threading.Thread(target=receving, args=("RecvThread",s))
  rT.start()
  
  alias = raw_input("Name: ")
  message = raw_input(alias + ": ")
  while message != 'q':
      if message != '':    
          s.sendto(alias + ": " + message, server)
      tLock.acquire()
      message = raw_input(alias + ": ")
      tLock.release()
      time.sleep(0.2)
  
  shudown = True
  rT.join()
  s.close()
  </code></pre>
  
  <p>What's wrong with the code? I've been searching around google, this website, and a few others, but can't seem to find anything. When I try the solutions they just don't work...
  Thanks for helping.</p>