我已经建立了UDP Pinger服务器端,但是此UDP Pinger客户端仅发送请求超时。我正在尝试创建一个向服务器发送10个ping的pinger。
import time
from socket import *
serverName = ''
serverPort = 12000
ClientSocket = socket(AF_INET, SOCK_DGRAM)
ClientSocket.settimeout(1)
ping = 1
message = 'ping'
counter = 10
i = 0
remain = counter - i
while counter < i :
i = i + 1
addr = ("", 120000)
start = time.time()
ClientSocket.sendto(message, (serverName,
serverPort))
while ping < 11:
try:
message, server = ClientSocket.recvfrom(1024)
end = time.time()
elapsed = end - start
print (message + " " + str(ping) + " " +
str(elapsed))
except timeout:
print ('REQUEST TIMED OUT')
ping = ping + 1