recv is not working as expected. I am sending 10 bytes (verified with wireshark) and recv is only getting the first byte and discarding the rest (until the next sendto). Is this a multicast thing? I'm pretty sure I've done this same thing with unicast UDP and had no issues.
Here is my example code:
import struct, socket, multiprocessing, time
MCAST_PORT = 62950
MCAST_GRP = '239.0.0.13'
def _Rx(self, RXsock, Queue):
print "Receiver started"
while True:
# State machine goes here to parse header and recv (<msglen>) bytes.
print "Waiting Rx char...", RXsock
char = RXsock.recv(1) # Blocks here after first byte ("1") ???
print "Rx", hex(ord(char))
TXsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
TXsock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
RXsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
RXsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
RXsock.bind((MCAST_GRP, MCAST_PORT))
mreq = struct.pack("4sl", socket.inet_aton(MCAST_GRP), socket.INADDR_ANY)
RXsock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
RxQueue = multiprocessing.Queue()
receiver = multiprocessing.Process(target=_Rx, args=(None, RXsock, RxQueue))
receiver.daemon = True
receiver.start()
TXsock.sendto("09123456789", (MCAST_GRP, MCAST_PORT))
time.sleep(3)