-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
54 lines (41 loc) · 1.32 KB
/
server.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
import signal, sys, ssl, logging, time, os
from input import Finder
import thread
import getopt
sys.path.append(os.path.abspath(os.path.curdir + '/vendor/SimpleWebSocketServer'))
from SimpleWebSocketServer import WebSocket, SimpleWebSocketServer, SimpleSSLWebSocketServer
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)
cam=1
debug=False
class InputServer(WebSocket):
def handleMessage(self):
if self.data is None:
self.data = ''
try:
self.sendMessage(str(self.data))
except Exception as n:
print(n)
def start_finder(self):
opts = {
'camera' : cam,
'debug' : debug
}
Finder().init(self, opts)
def handleConnected(self):
print(self.address, 'connected')
thread.start_new_thread(self.start_finder, ())
def handleClose(self):
print(self.address, 'closed')
if __name__ == "__main__":
def close_sig_handler(signal, frame):
server.close()
sys.exit()
opts, args = getopt.getopt(sys.argv[1:], 'c:')
for o, a in opts:
if o == 'c':
cam=0
elif o == 'd':
debug=True
signal.signal(signal.SIGINT, close_sig_handler)
server = SimpleWebSocketServer('0.0.0.0', 1337, InputServer)
server.serveforever()