Anders and Briegel in Python
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 8 gadiem
pirms 8 gadiem
pirms 8 gadiem
pirms 8 gadiem
pirms 8 gadiem
12345678910111213141516171819202122232425262728293031323334353637
  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()