-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeedTestClient.py
41 lines (27 loc) · 912 Bytes
/
speedTestClient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import socket
import sys
import select
from datetime import datetime,timedelta
def get_speed(host,port,recvlen):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
# Connect to server and send data
sock.connect((host, port))
length=0
timeout=5
running = True
starttime=datetime.now()
while running :
data = sock.recv(recvlen)
if len(data) != 0 :
length += len(data)
else :
break
timedelta = datetime.now() - starttime
print "Client received %d M data" % (length/1024/1024)
print "Speed is %fMbs"% ((length/1024/1024)/timedelta.total_seconds())
finally:
sock.close()
if __name__ == "__main__":
(hostname,port,datalen)=(sys.argv[1],int(sys.argv[2]),int(sys.argv[3]))
get_speed(hostname,port,datalen)