Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #83500 > unrolled thread

Re: OSError: [WinError 10022] An invalid argument was supplied in udp python file

Started byKev Dwyer <kevin.p.dwyer@gmail.com>
First post2015-01-10 11:43 +0000
Last post2015-01-10 11:43 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: OSError: [WinError 10022] An invalid argument was supplied in udp python file Kev Dwyer <kevin.p.dwyer@gmail.com> - 2015-01-10 11:43 +0000

#83500 — Re: OSError: [WinError 10022] An invalid argument was supplied in udp python file

FromKev Dwyer <kevin.p.dwyer@gmail.com>
Date2015-01-10 11:43 +0000
SubjectRe: OSError: [WinError 10022] An invalid argument was supplied in udp python file
Message-ID<mailman.17563.1420890228.18130.python-list@python.org>
contro opinion wrote:

> When i test an udp.py file on server and client in python34.
> 
> 
>     #!/usr/bin/env python
>     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 client 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 my message',('127.0.0.1', PORT))
>         print('Address after sending',s.getsockname())
>         data, address = s.recvfrom(MAX)
>         print('The server', address, 'says', repr(data))
>     else:
>       print('usage: udp_local.py server|client')
> 
> 
> The command `python udp.py server`  get output:
> Listening at ('127.0.0.1', 1060)
> 
> Why   `python udp.py client`  run failure:
> 
> Traceback (most recent call last):
>   File "d://udp.py", line 15, in <module>
>     print('Address before sending:', s.getsockname())
> OSError: [WinError 10022] An invalid argument was supplied


Hello,

According to http://stackoverflow.com/questions/15638214/socket-error-invalid-argument-supplied, the client socket doesn't have an address at time
when you call s.getsocketname.  This raises an exception on Windows.

Removing the 'Address before sending' line will prevent the error.

As you're using Python3, you'll find that passing strings to s.sendto raises
a TypeError; you'll need to encode the strings as bytes.

Hope that helps,

Kev

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web