Connection tester

David Shapiro David.Shapiro at sas.com
Wed Jun 10 16:41:36 CEST 2009


 Not al pages suppost GET.  If a page pings and returns does not mean it can be logged into and work (maybe database down).  Have you seen soapui?

----- Original Message -----
From: python-list-bounces+david.shapiro=sas.com at python.org <python-list-bounces+david.shapiro=sas.com at python.org>
To: python-list at python.org <python-list at python.org>
Sent: Wed Jun 10 10:26:22 2009
Subject: Connection tester

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:

    try:
        # 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)
        s.shutdown(SHUT_RDWR)

    except:
        result = ""

    # Check for problems and report back the time
    if result == "":
        return Result((time.time() - origTime) * 1000, True)
    else:
        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?
-- 
http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list