1from websocket_server import WebsocketServer
2
3# Called for every client connecting (after handshake)
4def new_client(client, server):
5	print("New client connected and was given id %d" % client['id'])
6	server.send_message_to_all("Hey all, a new client has joined us")
7
8
9# Called for every client disconnecting
10def client_left(client, server):
11	print("Client(%d) disconnected" % client['id'])
12
13
14# Called when a client sends a message
15def message_received(client, server, message):
16	if len(message) > 200:
17		message = message[:200]+'..'
18	print("Client(%d) said: %s" % (client['id'], message))
19
20
21PORT=9001
22server = WebsocketServer(PORT)
23server.set_fn_new_client(new_client)
24server.set_fn_client_left(client_left)
25server.set_fn_message_received(message_received)
26server.run_forever()
27