I'm getting the following error message:
Traceback (most recent call last):
File "UDPPingerClient2.py", line 20, in <module>
data, server = sock.recvfrom(1024)
ConnectionResetError: [WinError 10054] An existing connection was forcible closed by the remote host
I don't really know what the problem is seeing as other people in my class have used basically the same code and have gotten it to run right. Please help!
Here is my code which is in notepad++ and I am running it through a command prompt:
import socket
import time
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_addr = ('localhost', 12000)
sock.settimeout(1)
try:
for i in range(1, 11):
start = time.time()
message = 'Ping #' + str(i) + " " + time.ctime(start)
try:
sent = sock.sendto(message.encode(), server_addr)
print("Sent " + message)
data, server = sock.recvfrom(1024)
print("Received " + data.decode())
end = time.time();
elapsed = end - start
print("RTT: " + str(elapsed) + " seconds\n")
except socket.timeout:
print("#" + str(i) + " Requested Timed Out\n")
finally:
print("closing socket")
sock.close()