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.

34 lines
900B

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