"connection refused" error from UDP server???

Skip Montanaro skip at mojam.com
Wed Aug 18 20:49:48 CEST 1999

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

    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', ('', 10417))

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

What gives?

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

More information about the Python-list mailing list