Skip to content

Commit

Permalink
Binding reply receive socket before send request.
Browse files Browse the repository at this point in the history
Reply maybe comes fast while we are busy updating the screen or closing the
request socket, in this case replay is missed.
  • Loading branch information
LeeXiaolan committed Sep 23, 2016
1 parent c59d92c commit c5eaa41
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tddp-client/tddp-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ def validIP(ip):
tddp_digest = hashlib.md5(binascii.unhexlify(tddp_packet)).hexdigest()
tddp_packet = tddp_packet[:24] + tddp_digest + tddp_packet[56:]

# Binding receive socket in advance in case reply comes fast.
sock_receive = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock_receive.bind(('', port_receive))

# Send a request
sock_send = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock_send.sendto(binascii.unhexlify(tddp_packet), (ip, port_send))
Expand All @@ -191,8 +195,6 @@ def validIP(ip):
sock_send.close()

# Receive the reply
sock_receive = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock_receive.bind(('', port_receive))
response, addr = sock_receive.recvfrom(1024)
r = response.encode('hex')
if args.verbose:
Expand Down

0 comments on commit c5eaa41

Please sign in to comment.