diff options
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.") |