I'm trying to create a little program to listen to SSDP messages (they use multicast) in my local network. While the code works in WIndows 10 and shows me any multicast to the specified address, whenever I try to use it in my raspberry Pi 3, it shows nothing. I've been doing so many modifications trying to find the key but so far, no success.
The program runs, but there is no message coming from it. The code is the same in both platforms (well, IP addresses are different,
Can someone help me to find out where the problem might be as it's driving me crazy or helping me out with some tips? Thank you.
Code: Select all
import socket
import struct
import http.client
class ssdp(object):
def __init__(self, grupo=("239.255.255.250", 1900)):
self.group = grupo
self.numItems = 0
self.responses = []
return
def listen(self):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', self.group[1]))
mreq = struct.pack('4s4s', socket.inet_aton(self.group[0]), socket.inet_aton('192.168.1.42'))
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
while True:
print(sock.recv(1024))
return
respuesta = ssdp()
respuesta.listen()