I am working on developing an onvif device manager, more specifically the discovery part. To be able to connect over the internet, I need a python script on the local network’s server (debian12). The script is working if I run it om my windows 10 pc but not on my ubuntu 22 pc.
Here is my code:
def Discovery():
multicast_ip = "239.255.255.250"
multicast_port = 3702
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
my_ip = get_my_ip()
s.bind((my_ip, 0))
s.settimeout(2.0)
ret_value = []
# for i in range(2):
xml_str = get_soap(0)
s.sendto(xml_str.encode(), (multicast_ip, multicast_port))
count = 0
while True:
try:
data, address = s.recvfrom(65535)
found = False
for item in ret_value:
if item[0][0] == address[0]:
found = True
break
if found == True:
continue
ret_value.append((address, data))
count += 1
if count == 5:
break
except Exception as e:
ret_value = e
break
s.close()
return ret_value
if __name__ == '__main__':
data = Discovery()
print(data)
With WireShark I can see the request and the anwsers from both clients. The execution never returns from s.recvfrom if timeout not is set. I also tryed s.recvfrom_into. What can be wrong? Any ideas?