-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket_prog.py
executable file
·61 lines (50 loc) · 1013 Bytes
/
socket_prog.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
# Import modules
import sys
import socket
import time
# Create socket object
s = socket.socket()
print s
def get_command(command):
print s
# Send ENQ and check ACK
s.send('\x05')
#time.sleep(.1)
rsp = s.recv(1)
while rsp != '\x06':
s.send('\x05')
#time.sleep(.1)
rsp = s.recv(1)
# Send command
s.send(command)
#time.sleep(.1)
# Wait for ENQ
rsp = s.recv(1)
while rsp != '\x05':
print 'Waiting for ENQ'
rsp = s.recv(1)
s.send('\x06')
time.sleep(.1)
rsp = s.recv(1024)
print rsp
return 1
def main(unused):
# Host IP Address and Port Number
host_ip = '172.26.67.100'
host_port = 10001
print s
# Establish connection
s.connect((host_ip, host_port))
for i in xrange(5):
print i
start = time.time()
get_command('\x02CD\x03')
print time.time() - start
get_command('\x02DHT\x03')
return 0
# Close connection
s.close()
print s
if __name__ == '__main__':
sys.exit(main(sys.argv))