summaryrefslogtreecommitdiff
path: root/server.py
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2020-12-16 16:16:27 -0300
committerJesusaves <cpntb1@ymail.com>2020-12-16 16:16:27 -0300
commitb8d0795d491e8a68abe968d92898abeb1b9c4c26 (patch)
tree168eef73bb36cf050defe40cbe1ce313ed8a05cb /server.py
parent467fc51d8886b4973bf572ba58b05f20f3f14c85 (diff)
downloadserver-b8d0795d491e8a68abe968d92898abeb1b9c4c26.tar.gz
server-b8d0795d491e8a68abe968d92898abeb1b9c4c26.tar.bz2
server-b8d0795d491e8a68abe968d92898abeb1b9c4c26.tar.xz
server-b8d0795d491e8a68abe968d92898abeb1b9c4c26.zip
Add utils for improved logging.
Add the placeholder JSONs from earlier.
Diffstat (limited to 'server.py')
-rwxr-xr-xserver.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/server.py b/server.py
index a6e66c1..f461b82 100755
--- a/server.py
+++ b/server.py
@@ -1,9 +1,10 @@
#!/usr/bin/python3
-import threading, time, json, ssl
+import threading, time, json#, ssl
#from simple_websocket_server import WebSocketServer, WebSocket
from websock import WebSocketServer, WebSocket
#from endpoint import MainEndpoint
+from utils import stdout as stdout
###############################################################
# Configuration
@@ -29,6 +30,7 @@ class WebSocketConn(WebSocket):
If the frame is Binary then self.data is a bytearray object.
"""
print("Message received from %s - %s" % (self.address[0], self.data))
+ #stdout(self.address[0] + u' - %s' % (self.data))
self.send_message('ACK')
def connected(self):
@@ -37,14 +39,15 @@ class WebSocketConn(WebSocket):
Called when a websocket client connects to the server.
"""
print(self.address, 'connected')
- for client in clients:
- print(repr(client))
- client.send_message(self.address[0] + u' - connected')
+ #for client in clients:
+ # print(repr(client))
+ # client.send_message(self.address[0] + u' - connected')
+ stdout(self.address[0] + u' - connected')
# TODO: Drop OLD connections when same ID tries to connect
if (False):
- close(self, status=1000, reason='Unrecognized')
+ self.close(self, status=1000, reason='Unrecognized')
else:
clients.append(self)
@@ -55,8 +58,9 @@ class WebSocketConn(WebSocket):
"""
clients.remove(self)
print(self.address, 'closed')
- for client in clients:
- client.send_message(self.address[0] + u' - disconnected')
+ #for client in clients:
+ # client.send_message(self.address[0] + u' - disconnected')
+ stdout(self.address[0] + u' - disconnected')
##########################
# Useful functions:
@@ -98,16 +102,17 @@ def sendmsg(m, t="raw"):
###############################################################
# Begin stuff
-print("Starting...")
+stdout("Starting...")
MainWebsocket()
-print("Please wait...")
try:
+ print("Running...")
while True:
time.sleep(15)
sendmsg("Hello from SRV")
except:
- print("Terminating!")
-
+ stdout("Terminating!")
+# TODO: Cleanup here
+print("Server finished.")