-from weakref import WeakKeyDictionary, proxy
+__all__ = ('Connection',
+from weakref import proxy
from functools import partial
from packet import PacketManager
- """Class allowing to send
messages and packets
+ """Class allowing to send packets
- peer - connection to send packet over
- channel - channel of connection
+ It's created by by Client or Server, shouldn't be created manually.
- # chat_msg packet is defined in packets module
- client.net_chat_msg('Tom', 'Test message')
- client.send(packets.chat_msg('Tom', 'Test message'))
+ Sending is possible in two ways:
+ * using net_<packet_name> methods, where <packet_name>
+ is name of packet registered in PacketManager
+ * using send method with packet as argument
+ parent - proxy to Client / Server instance
+ peer - Enet peer instance
def __init__(self, parent, peer, packet_manager=PacketManager):
def send(self, packet, *args, **kwargs):
"""Send packet to remote host
lient.send(packet, *args, **kwargs): return int
+ C.send(packet, *args, **kwargs): return int
packet - class created by PacketManager.register or packet name
+ """Request a disconnection.
+ """Request a disconnection from a peer, but only after all queued
+ outgoing packets are sent.
+ def disconnect_now(self):
+ """Force an immediate disconnection.
def add_receiver(self, receiver):
+ """Add new Receiver to handle packets.
+ receiver - instance of Receiver subclass
receiver.connection = proxy(self)
+ """Connection state."""
+ """Connection address."""
- def on_disconnect(self):
- def on_recive(self, channel, packet_id, packet):