Message117155
| Author |
neologix |
| Recipients |
BreamoreBoy, abgrover, neologix |
| Date |
2010年09月22日.21:17:18 |
| SpamBayes Score |
5.1014748e-14 |
| Marked as misclassified |
No |
| Message-id |
<1285190240.69.0.704165167085.issue1462440@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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 |
| 2010年09月22日 21:17:20 | neologix | set | recipients:
+ neologix, abgrover, BreamoreBoy |
| 2010年09月22日 21:17:20 | neologix | set | messageid: <1285190240.69.0.704165167085.issue1462440@psf.upfronthosting.co.za> |
| 2010年09月22日 21:17:19 | neologix | link | issue1462440 messages |
| 2010年09月22日 21:17:18 | neologix | create |
|