"connection refused" error from UDP server???

Skip Montanaro skip at mojam.com
Wed Aug 18 14:49:48 EDT 1999


I'm running a simple UDP echo server based on the sample in the Python
distribution:

    def server(port, verbose=0):
	signal.signal(signal.SIGHUP, exithandler)
	s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	s.bind('', port)
	while 1:
	    data, addr = s.recvfrom(BUFSIZE)
	    if verbose: sys.stdout.write(data)
	    s.sendto(data, addr)

When I run it, I get a "connection refused" message on the recvfrom call
when it's pinged:

    >>> import udpecho
    >>> udpecho.server(10417, 1)


    Traceback (innermost last):
      File "<stdin>", line 1, in ?
      File "/usr/local/lib/automatrix/python/udpecho.py", line 53, in server
	data, addr = s.recvfrom(BUFSIZE)
    socket.error: (111, 'Connection refused')

even though on the other end, things seem to complete okay:

    >>> sockmisc.ping("localhost", 10417)
    ?? ('\012', ('127.0.0.1', 10417))
    0.01

(The line beginning "??" echoes the response from the server and its
address.)

What gives?

Skip Montanaro	| http://www.mojam.com/
skip at mojam.com  | http://www.musi-cal.com/~skip/
847-971-7098




More information about the Python-list mailing list