-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
83 lines (65 loc) · 2.12 KB
/
Copy pathserver.py
File metadata and controls
83 lines (65 loc) · 2.12 KB
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
import tornado.ioloop
import tornado.web
import tornado.websocket
from os import listdir
cvrDirectoryString = "."
try:
coot_version()
except NameError:
runningInCoot = False
print("Not running in coot")
ip = "localhost"
else:
cvrDirectoryString = "CVR"
runningInCoot = True
print("Running in coot")
import imp
serverReactions = imp.load_source('serverReactionsName', '/home/htodd/CVR/serverReactions.py')
ip = "192.168.56.101"
port = 9090
print("websocket (NOT address bar) link: " + ip + ":" + str(port))
class wsHandler(tornado.websocket.WebSocketHandler):
def check_origin(self, origin):
return True
def open(self):
self.set_nodelay(True)
print('Opened connection')
if runningInCoot == True:
serverReactions.connect(self)
else:
self.write_message({"command":"you aren't connected to coot"})
def on_message(self, msgContainer):
msg = eval(msgContainer) #TODO unsecure
if msg["command"] == "pdbAndMapFilenames":
returnMsg = {"command":"pdbAndMapFilenames"}
returnMsg["filenames"] = listdir(cvrDirectoryString + "/modelsAndMaps")
self.write_message(returnMsg)
if msg["command"] == "loadPolarAndAzimuthals":
file = open( cvrDirectoryString + "/settings/" + "polarAndAzimuthals.txt","r" )
returnMsg = {"command":"polarAndAzimuthals"}
returnMsg["polarAndAzimuthals"] = file.read()
file.close()
self.write_message(returnMsg)
if msg["command"] == "savePolarAndAzimuthals":
file = open( cvrDirectoryString + "/settings/" + "polarAndAzimuthals.txt","w" )
file.write( str(msg["polarAndAzimuthals"]) )
file.close()
elif runningInCoot == True:
serverReactions.command(msg)
def on_close(self):
print('Closed connection')
application = tornado.web.Application([(r'/ws', wsHandler)])
application.listen(port)
#---------------So that you can ctrl+c
isClosing = False
def signalHandler(signum, frame):
global isClosing
isClosing = True
def tryExit():
global isClosing
if isClosing:
tornado.ioloop.IOLoop.instance().stop()
import signal
signal.signal(signal.SIGINT, signalHandler)
tornado.ioloop.PeriodicCallback(tryExit, 100).start()
tornado.ioloop.IOLoop.instance().start()