我有下面的代码。现在,我只是将sequence number
和ACK
放入有效负载中。我想知道两件事:
我正在Linux上使用Python 2.7.13。
客户:
import socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client_socket.settimeout(4.0)
message = "Sequence Number: 100\nACK: 1"
addr = ("127.0.0.1", 6000)
client_socket.sendto(message, addr)
try:
data, server = client_socket.recvfrom(1024)
# Print the ACK the server sent
except socket.timeout:
print('Timed out')
服务器:
import socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.bind(("127.0.0.1", 6000))
while True:
message, address = server_socket.recvfrom(1024)
# Print the sequence number the client sent
# Set ACK to 0 and send this ACK to the client
server_socket.sendto(message, address)