-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzmqtest.py
56 lines (47 loc) · 1.29 KB
/
zmqtest.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
import zmq
import platform
import time
from random import randint
#if platform.system == 'Windows':
import msvcrt
def kbfunc():
x = msvcrt.kbhit()
if x:
ret = ord(msvcrt.getch())
else:
ret = 0
return ret
"""
elif platform.system == 'Linux':
import sys
import select
def heardEnter():
i,o,e = select.select([sys.stdin],[],[],0.0001)
for s in i:
if s == sys.stdin:
input = sys.stdin.readline()
return True
return False
"""
#initialize zmq
context = zmq.Context()
#socketIn = context.socket(zmq.SUB)
socketOut = context.socket(zmq.PAIR)
#portIn = "5557"
portOut = "5555"
#socketIn.connect("tcp://127.0.0.1:%s" % portIn)
#socketOut.bind("tcp://127.0.0.1:%s" % portOut)
socketOut.bind("tcp://192.168.2.245:%s" % portOut)
msgs = ("ZT", "TQB", "TQE", "IB", "IE", "MQQ0A1B2", "MKW0B2C2")
keepRunning = True
zerotime = time.time()
while keepRunning:
msg = msgs[randint(0, len(msgs)-1)]
if msg == "ZT":
zerotime = time.time()
socketOut.send("%s" % msg)#("p", msg))
print "sending %s, time: %s" % (msg, time.time()-zerotime)
#socketOut.send("%s %s" % ("you_will_never_see_me", "crapperjack"))
time.sleep(0.25)
if kbfunc() != 0:
keepRunning = False