-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
89 lines (71 loc) · 2.42 KB
/
Main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
__author__ = 'hut-dell'
import zmq
import random
import sys
import time
import threading
class StartForwarders(threading.Thread):
def __init__(self, direction):
threading.Thread.__init__(self)
self.direction = direction
def run(self):
didrun = False
print "self.direction = " + str(self.direction)
print ""
print ""
if(self.direction == "UnityToOpencog"):
try:
context = zmq.Context(1)
# Unity Pub Facing
frontend = context.socket(zmq.SUB)
frontend.bind("tcp://*:5559")
frontend.setsockopt(zmq.SUBSCRIBE, "")
# Python Sub Facing
backend = context.socket(zmq.PUB)
backend.bind("tcp://*:5560")
print "launching UnityToOpenCog forwarder Port:5559 for PUB Port:5560 for SUB "
didrun = True
zmq.device(zmq.FORWARDER, frontend, backend)
except Exception, e:
print e
print "bringing down zmq device"
finally:
pass
frontend.close()
backend.close()
context.term()
if(self.direction == "OpencogToUnity"):
try:
context = zmq.Context(1)
# Python Sub Facing
frontend = context.socket(zmq.SUB)
frontend.bind("tcp://*:5561")
frontend.setsockopt(zmq.SUBSCRIBE, "")
# Unity Sub facing
backend = context.socket(zmq.PUB)
backend.bind("tcp://*:5562")
print "launching OpenCogToUnity forwarder Port:5561 for PUB Port:5562 for SUB"
didrun = True
zmq.device(zmq.FORWARDER, frontend, backend)
except Exception, e:
print e
print "bringing down zmq device"
finally:
pass
frontend.close()
backend.close()
context.term()
if(didrun == False):
print "did not run " + str(self.direction)
thread1 = StartForwarders("UnityToOpencog")
thread2 = StartForwarders("OpencogToUnity")
thread3 = StartForwarders("Random Bullshit")
thread1.start()
thread2.start()
thread3.start()
kount = 0
#print ("starting while(true) loop")
while(True):
kount = kount + 1
print kount
time.sleep(5)