forked from ReflectionsProjections/mm22
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsocket_server.py
More file actions
executable file
·33 lines (24 loc) · 891 Bytes
/
websocket_server.py
File metadata and controls
executable file
·33 lines (24 loc) · 891 Bytes
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
#!/usr/bin/env python2
from SimpleWebSocketServer import SimpleWebSocketServer, WebSocket
import src.misc_constants as misc_constants
import json
class WebSocketServer(WebSocket):
def handleMessage(self):
# method gets called when server is pinged
# use self.data to access incoming data
# self.sendMessage(self.data)
return
def handleConnected(self):
# Read json for data and send it
print(self.address, 'connected')
data = []
with open(misc_constants.logFile, "r") as file:
if file:
for line in file.readlines():
data.append(json.loads(line))
self.sendMessage(json.dumps({"data": data}))
def handleClose(self):
print(self.address, 'closed')
# WebSocket Server
server = SimpleWebSocketServer('', 8080, WebSocketServer)
server.serveforever()