Browse Source

Stopped WebSocket client from hanging :gun:

By default the server echoes messages to all clients.
The fancy.GraphState client was never calling ws.recv()
And hence a buffer was filling up somewhere
And we were hanging.
Adding a ws.recv() fixed the problem.
master
Pete Shadbolt 7 years ago
parent
commit
548f7f59e0
2 changed files with 10 additions and 2 deletions
  1. +2
    -1
      abp/fancy.py
  2. +8
    -1
      abp/server.py

+ 2
- 1
abp/fancy.py View File

@@ -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):


+ 8
- 1
abp/server.py View File

@@ -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)


Loading…
Cancel
Save