Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 04 Jan 2006 14:52:02 +1030
From:      Bob Halley <Bob.Halley@nominum.com>
To:        freebsd-net@freebsd.org
Subject:   Re: Unexpected EADDRINUSE
Message-ID:  <43BB4D6A.8030703@nominum.com>
In-Reply-To: <43BB4C59.3010800@nominum.com>
References:  <43BB4C59.3010800@nominum.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Sorry my attachments didn't make it :)

#
# sink.py
#
import socket
import traceback

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('127.0.0.1', 12345))
s.listen(5)

while True:
    try:
        n = s.accept()[0]
        d = None
        while d != '':
            d = n.recv(100)
        n.close()
    except socket.error:
        pass


#
# conn.py
#
import socket
import traceback

n = 0
while True:
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        s.bind(('127.0.0.1', 0))
        print s.getsockname()
        s.connect(('127.0.0.1', 12345))
        s.close()
        n += 1
        if n > 0 and n % 1000 == 0:
            print n
    except Exception, e:
        traceback.print_exc()
        break
print n




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?43BB4D6A.8030703>