运行此程序时出现此错误。我是socket编程的新手,所以我不确定这个错误是什么。
如果SOme可以提供一个解释和一个解决方案,那就太棒了
第23行,在 message,address = clientSocket.recvfrom(1024) 错误:[Errno 10054]远程主机强制关闭现有连接
from socket import *
import time
print ("Running")
serverName = '127.0.0.1'
clientSocket = socket(AF_INET,SOCK_DGRAM)
clientSocket.settimeout(1)
sequence_number = 1
while sequence_number<=10:
message = "Ping"
start=time.time()
clientSocket.sendto(message.encode(),(serverName, 8000))
try:
message, address = clientSocket.recvfrom(1024)
elapsed = (time.time()-start)
print (sequence_number)
print (message)
print ("Round Trip Time is:" + str(elapsed) + "seconds" )
except timeout:
print (sequence_number)
print ("Request timed out")
sequence_number+=1
if sequence_number > 10:
clientSocket.close()