python - UDP Connect Cause Socket To Lose Packets? -
python - UDP Connect Cause Socket To Lose Packets? -
i debugging python program, application can't receive udp packets expected. found udpsocket.connect cause udpsocket lose these packets. see below code:
def main: sock = socket.socket(socket.af_inet, socket.sock_dgram) sock.connect((server_ip, 9)) #this results in issue #use sock.bind((local_ip, 12345)) #instead solve problem localip, localport = sock.getsockname() packet = getregisterdata(localip, localport) sock.sendto(packet, (server_ip, 5000)) #the host (server_ip, 5000) #always send 2 udp packets #to respond statement sleep(1) while true: response = sock.recv(1024) #packets (server_ip, 5000) reached #machine statement never homecoming if not len(response) break print response i new python, , don't understand why happen. body helps explain this?
[update] utilize tcpdump capture packets, find lost packets have reached machine, due unkown reason sock.recv doesn't retuern. want help explain why sock.recv doesn't homecoming everytime here.
you didn't mention packets expect receive (but fail to) coming from. i'm guessing they're not coming address connected to, though. see man page connect(2) - you're calling when utilize python api - info why matters. in particular:
if socket sockfd of type sock_dgram addr address datagrams sent default, , the address datagrams received.
(emphasis mine).
python linux sockets networking
Comments
Post a Comment