-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch_server.py
55 lines (39 loc) · 1.43 KB
/
watch_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
54
55
import argparse
import os
import io
import tornado.ioloop
import tornado.web
import tornado.websocket
import socket
import json
scanner_clients = []
class SVGWebSocket(tornado.websocket.WebSocketHandler):
def check_origin(self, origin):
return True # accept all cross-origin traffic, not very secure...
def open(self):
scanner_clients.append(self)
print("SVGWebSocket opened from: " + self.request.remote_ip)
def on_message(self, message):
print(json.loads(message))
def on_close(self):
scanner_clients.remove(self)
print("SVGWebSocket closed from: " + self.request.remote_ip)
if __name__ == "__main__":
# API
parser = argparse.ArgumentParser(description='Start the streaming server.')
parser.add_argument('--port', default=8888, type=int, help='Web server port (default: 8888)')
args = parser.parse_args()
script_path = os.path.dirname(os.path.realpath(__file__))
static_path = script_path + '/static/'
app = tornado.web.Application([
(r"/svg", SVGWebSocket)
])
app.listen(args.port)
print("Starting server: http://localhost:" + str(args.port) + "/")
host_ip_address = socket.gethostbyname(socket.gethostname())
print("Host IP Address: " + host_ip_address)
try:
tornado.ioloop.IOLoop.current().start()
# START OBSERVER
except KeyboardInterrupt:
print("Stopping server ...")