Created
February 19, 2012 07:56
-
-
Save newhouseb/1862521 to your computer and use it in GitHub Desktop.
DIY Speedtest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# curl http://[yourhost]:2014 > /dev/null | |
# This will show average download speed for infinity client-side, until you ctrl-c | |
# The server prints a rolling average of the connection speed (can only accept one connection at a time) | |
import socket | |
import time | |
host = '' | |
port = 2014 | |
backlog = 5 | |
size = 1024 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
s.bind((host,port)) | |
s.listen(backlog) | |
while 1: | |
client, address = s.accept() | |
print "Connection Opened", address | |
sent = 0 | |
data = client.recv(size) | |
start = time.time() | |
if data: | |
client.send('HTTP 200 OK\r\n\r\n') | |
while 1: | |
try: | |
client.settimeout(5.0) | |
this_send = client.send('a'*1024) | |
if this_send <= 0: | |
break | |
sent += this_send | |
print " status ", (sent/1024.0)/float(time.time() - start), sent, time.time() - start | |
except Exception as e: | |
print e | |
break | |
print "Done ", (sent/1024.0)/float(time.time() - start), sent, time.time() - start | |
client.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment