1

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()
melpomene
  • 84,125
  • 8
  • 85
  • 148
Morgyn
  • 11
  • 1
  • 2
    [MSDN](https://msdn.microsoft.com/en-us/library/windows/desktop/ms740120(v=vs.85).aspx) says: "*On a UDP-datagram socket this error indicates a previous send operation resulted in an ICMP Port Unreachable message.*" I.e. the `sendto` call ran into an error. Is there a server running on `localhost:12000`? – melpomene Dec 10 '16 at 23:00
  • @CareyGregory You're thinking of TCP. This is UDP. – user207421 Dec 10 '16 at 23:24
  • @EJP Oops, you're right. Comment deleted. – Carey Gregory Dec 11 '16 at 05:30

0 Answers0