diff --git a/abp/fancy.py b/abp/fancy.py index 8311d33..cdc4813 100644 --- a/abp/fancy.py +++ b/abp/fancy.py @@ -15,7 +15,7 @@ class GraphState(graphstate.GraphState, networkx.Graph): def connect_to_server(self, uri = "ws://localhost:5000"): """ Attempt to connect to the websocket server """ try: - self.ws = websocket.create_connection(uri) + self.ws = websocket.create_connection(uri, timeout=0.1) atexit.register(self.shutdown) except socket_error: self.ws = None @@ -39,6 +39,7 @@ class GraphState(graphstate.GraphState, networkx.Graph): # Send data to browser and rate-limit self.ws.send(json.dumps(self.to_json(), default = str)) + self.ws.recv() time.sleep(delay) def layout(self, dim=3): diff --git a/abp/server.py b/abp/server.py index a0f909b..8964415 100644 --- a/abp/server.py +++ b/abp/server.py @@ -3,6 +3,7 @@ from SimpleHTTPServer import SimpleHTTPRequestHandler from BaseHTTPServer import HTTPServer import os, sys, threading import webbrowser +import argparse clients = [] @@ -19,6 +20,10 @@ def client_left(client, server): clients.remove(client) if __name__ == '__main__': + parser = argparse.ArgumentParser(description = "ABP websocket server") + parser.add_argument("-v", action="store_true", help="Launch browser") + args = parser.parse_args() + # Change to the right working dir where = os.path.join(sys.path[0], "../static") os.chdir(where) @@ -28,7 +33,9 @@ if __name__ == '__main__': thread = threading.Thread(target = httpserver.serve_forever) thread.daemon = True thread.start() - webbrowser.open("http://localhost:5001/") + + if args.v: + webbrowser.open("http://localhost:5001/") # Start the websocket server server = WebsocketServer(5000)