Connection tester

Sparky Samnsparky at
Wed Jun 10 10:26:22 EDT 2009

Hey! I am developing a small application that tests multiple websites
and compares their "response time". Some of these sites do not respond
to a ping and, for the measurement to be standardized, all sites must
have the same action preformed upon them. Another problem is that not
all of the sites have the same page size and I am not interested in
how long it takes to load a page but instead just how long it takes
for the website to respond. Finally, I am looking to keep this script
platform independent, if at all possible.

Here is the code:

        # Get the starting time
        origTime = time.time()

        # Create the socket connection and then close
        s = socket.socket(AF_INET, SOCK_STREAM)
        s.connect((targetIP, port))
        s.send("GET / HTTP/1.0\r\n\r\n")
        result = s.recv(1024)

        result = ""

    # Check for problems and report back the time
    if result == "":
        return Result((time.time() - origTime) * 1000, True)
        return Result((time.time() - origTime) * 1000, False)

Result is just an object that holds the time it took for the method to
finish and if there were any errors. What I am worried about is that
the socket is potentially closed before the website can finish sending
in all the data. Does anyone have any suggestions or is the script
fine as it is?

More information about the Python-list mailing list