title: Socket.error: Invalid Argument supplied
body: <p>I am learning networking programming and trying to grasp the basics of sockets through this example.</p>
  
  <pre><code>import socket,sys
  
  
  s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
  
  MAX = 65535
  PORT = 1060
  
  if sys.argv[1:] == ['server']:
      s.bind(('127.0.0.1',PORT))
      print 'Listening at ' , s.getsockname()
      while True:
          data,address = s.recvfrom(MAX)
          print ' The address at ' , address , ' says ' , repr(data)
          s.sendto('your data was %d bytes' % len(data),address)
  
  elif  sys.argv[1:] == ['client']:
      print ' Address before sending ' ,s.getsockname()
      s.sendto('This is the message',('127.0.0.1',PORT))
      print ' Address after sending ' ,s.getsockname()
      data,address = s.recvfrom(MAX)
      print ' The server at ' , address , ' says ' , repr(data)
  
  else:
      print &gt;&gt; sys.stderr, 'usage: udp_local.py server | client '
  </code></pre>
  
  <p>However,its throwing up an exception saying the arguments given by getsockname() were invalid specifically on line 22.The code is correct as far as I know.Here's the exception</p>
  
  <pre><code>Traceback (most recent call last):
    File "udp_local.py", line 23, in &lt;module&gt;
      print ' Address before sending ' ,s.getsockname()
    File "c:\Python27\lib\socket.py", line 224, in meth
      return getattr(self._sock,name)(*args)
  error: [Errno 10022] An invalid argument was supplied
  </code></pre>
  
  <p>Using PyScripter 2.5.3.0 x86 </p>