-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimingclient.py
More file actions
43 lines (33 loc) · 917 Bytes
/
timingclient.py
File metadata and controls
43 lines (33 loc) · 917 Bytes
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
42
import threading
import time
import socket
def make_connection(host, port, data_to_send):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.send(data_to_send)
s.send('\r\n')
b = []
while True:
data = s.recv(1024)
if data:
b.append(data)
else:
break
return ''.join(b)
def t_connection(host, port, d):
start = time.time()
make_connection(host, port, d)
print d, 'took', time.time() - start
if __name__ == '__main__':
import sys
host, port = sys.argv[1].split(':')
data_to_send = sys.argv[2:]
threads = []
overallstart = time.time()
for d in data_to_send:
t = threading.Thread(target=t_connection, args=(host, int(port), d))
t.start()
threads.append(t)
for t in threads:
t.join()
print 'FINISHED in', time.time() - overallstart