thiezn / iperf3-python

Python wrapper around iperf3
https://iperf3-python.readthedocs.org/
MIT License
109 stars 52 forks source link

Client connection resilience on busy #46

Open pau1a opened 5 years ago

pau1a commented 5 years ago

Im trying to add some resilience to my clients such that if they attempt to connect to a port on the server that is busy, they automatically increment the port number within the range of open server ports. This is what I am trying. The problem is it seems never to trigger the exception. If I make port 5200 busy with another client, the test seems just to fail silently. Surely I can't be the first person to attempt this. Any ideas how I can force a retry?

client = iperf3.Client()
client.duration = 15
client.server_hostname = 'x.x.x.x'
client.verbose = True
client.reverse = True
print('a')
i = 0
while i < 9:
        print('b')
        try:
                client.port = 5200 + i
                print('c')
                result = client.run()
                print(result.received_Mbps)
                i = 10
                print(str(client.port))
        except:
                i = i + 1