This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2006年03月31日 22:16 by abgrover, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| multicastbug.py | abgrover, 2006年04月05日 12:55 | script to reproduce | ||
| multicastbug.py | abgrover, 2006年04月05日 12:58 | script to reproduce | ||
| Messages (4) | |||
|---|---|---|---|
| msg28006 - (view) | Author: Alan G (abgrover) | Date: 2006年03月31日 22:16 | |
Using setsockopt to join a multicast group for a udp socket fails on windows (works on linux). Test reproduction: run the attached file expected behavior: The snd thread sends three udp packets to the multicast address. The rcv thread reads three udp packets. observed behavior on linux: the expected behavior observed behavior on windows: Exception in thread rcv: Traceback (most recent call last): File "C:\Python24\lib\threading.py", line 442, in __bootstrap self.run() File "C:\Python24\lib\threading.py", line 422, in run self.__target(*self.__args, **self.__kwargs) File "E:\svn\TTC\trunk\agrover\src\SmcTestCase\multicastbug.py", line 12, in rcv s.setsockopt(SOL_IP, IP_ADD_MEMBERSHIP, sopt) File "<string>", line 1, in setsockopt error: (10022, 'Invalid argument') |
|||
| msg28007 - (view) | Author: Alan G (abgrover) | Date: 2006年04月05日 12:57 | |
Logged In: YES user_id=1098341 More details of config: Windows used is XP Pro SP2 Linuxen used include Fedora Core and Mandrake |
|||
| msg114648 - (view) | Author: Mark Lawrence (BreamoreBoy) * | Date: 2010年08月22日 08:54 | |
I can't reproduce this on Windows Vista can someone please confirm my findings. |
|||
| msg117155 - (view) | Author: Charles-François Natali (neologix) * (Python committer) | Date: 2010年09月22日 21:17 | |
I tested it on a Windows XP box, and encountered the same problem.
The error is raised because Windows XP requires the socket to be bound before calling setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq).
So calling bind() before setsockopt() solves this error.
But then you also need to specify for the sender the interface to use using setsockopt(IPPROTO_IP, IP_MULTICAST_IF, address)
Here's a working example:
---- sender ----
from socket import *
s = socket(AF_INET, SOCK_DGRAM)
s.setsockopt(IPPROTO_IP, IP_MULTICAST_IF, inet_aton('127.0.0.1'))
s.sendto(b'foo', ('224.0.0.1', 4242))
----------------
--- receiver ---
from socket import *
s = socket(AF_INET, SOCK_DGRAM)
s.bind(('127.0.0.1', 4242))
mreq = inet_aton('224.0.0.1') + inet_aton('127.0.0.1')
s.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq)
s.recv(100)
----------------
So it's not a Python bug.
Since multicast is tricky, it might be a good idea to add a short example somewhere in the documentation though.
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:16 | admin | set | github: 43134 |
| 2011年08月30日 18:34:35 | neologix | set | status: open -> closed resolution: not a bug stage: needs patch -> resolved |
| 2010年09月22日 21:17:19 | neologix | set | nosy:
+ neologix messages: + msg117155 |
| 2010年08月22日 08:54:58 | BreamoreBoy | set | nosy:
+ BreamoreBoy messages: + msg114648 versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6, Python 3.0 |
| 2009年03月21日 02:03:07 | ajaksu2 | set | title: udp multicast setsockopt fails -> socket and threading: udp multicast setsockopt fails stage: needs patch type: behavior components: + Extension Modules versions: + Python 2.6, Python 3.0, - Python 2.4 |
| 2006年03月31日 22:16:42 | abgrover | create | |