A
A
Alexey Zhurbitsky2011-06-17 17:27:12
Python
Alexey Zhurbitsky, 2011-06-17 17:27:12

Python multicast receiver - duplicate packets?

There is a script that opens a socket and reads a multicast from it (taken from here )

import socket
import struct

MCAST_GRP = '224.1.1.1'
MCAST_PORT = 1234

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', MCAST_PORT))
mreq = struct.pack("4sl", socket.inet_aton(MCAST_GRP), socket.INADDR_ANY)

sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)

while True:
  print sock.recv(10240)


everything is fine until I run the same script in parallel on another multicast group, but the ports are the same, for example
rtp://224.1.1.1:1234
rtp://224.1.1.2:
1234 second, and the second for the first.

I tried to do it as in mcast.py , the result is similar.

Why does this happen and how to cure it?

UPD. It was solved by substituting the addresses of the multicast group in sock.bind
-sock.bind(('', MCAST_PORT))
+sock.bind((MCAST_GRP, MCAST_PORT))

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question