Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
969B

  1. from websocket_server import WebsocketServer
  2. import threading
  3. import abp
  4. import json
  5. clients = []
  6. state = abp.VisibleGraphState()
  7. def compute_diff(decoded_message):
  8. def new_message(client, server, message):
  9. decoded_message = json.loads(message)
  10. if "diff" in decoded_message:
  11. server.send_message_to_all(message)
  12. elif "method" in decoded_message:
  13. message = compute_diff(decoded_message)
  14. server.send_message_to_all(message)
  15. else:
  16. print "Could not interpret message"
  17. def new_client(client, server):
  18. print "Client {} connected.".format(client["id"])
  19. clients.append(client)
  20. def client_left(client, server):
  21. print "Client {} disconnected.".format(client["id"])
  22. clients.remove(client)
  23. if __name__ == '__main__':
  24. server = WebsocketServer(5001)
  25. server.set_fn_new_client(new_client)
  26. server.set_fn_message_received(new_message)
  27. server.set_fn_client_left(client_left)
  28. server.run_forever()