socktools.tools.examples.gen_proto.chat_client¶
To run this, make sure chat_server.py is running first, it will bind to port 31337 by default.
Note
This example requires you to first build the chat_protocol.json file using gen_proto.
-
class
socktools.tools.examples.gen_proto.chat_client.ChatHandlers(bind=None, connect=None, handlers={}, timeout=10, tick_interval=0.25, sock=None, meta_sock=None, logger=None, no_async=False)[source]¶ Bases:
socktools.tools.examples.gen_proto.generated.ChatProtocolClient implementation for the chat protocol
Similar to the server implementation, this class simply inherits and adds handlers
-
do_ping()[source]¶ Sends ping packets to the server
To make things simpler, we send ping packets out but we don’t bother tracking them - they exist only to keep the connection alive. ping_id is simply int(time.time())
-
handle_msg(from_addr, msg_text=None)[source]¶ Handle chat messages
Since this is the client, we dump messages to stdout
Parameters: from_addr (tuple) – Represents the TCP/IP endpoint the message came from in (address,port) format Keyword Arguments: msg_text (str) – The text of the message
-
handle_ping(from_addr, ping_id=None)[source]¶ Handle ping packets
Identical to the one in chat_server.py
Parameters: from_addr (tuple) – Represents the TCP/IP endpoint the message came from in (address,port) format Keyword Arguments: ping_id (int) – In a “real” server this would be the ping ID that needs to be acknowledged with a corresponding PONG message back.
-