diff options
author | Jesusaves <cpntb1@ymail.com> | 2020-12-16 16:16:27 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2020-12-16 16:16:27 -0300 |
commit | b8d0795d491e8a68abe968d92898abeb1b9c4c26 (patch) | |
tree | 168eef73bb36cf050defe40cbe1ce313ed8a05cb /server.py | |
parent | 467fc51d8886b4973bf572ba58b05f20f3f14c85 (diff) | |
download | server-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-x | server.py | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -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.") |