Package horizons :: Package network :: Module connection :: Class Connection
[hide private]
[frames] | no frames]

Class Connection

source code

Low-level interface to enet.

Handles sending and receiving packets.

Instance Methods [hide private]
 
__init__(self, process_async_packet, server_address, client_address=None) source code
 
is_connected(self) source code
 
connect(self)
Connect to master server.
source code
 
disconnect(self, server_may_disconnect=False)
End connection to master server.
source code
 
ping(self)
Handle incoming packets.
source code
 
send_packet(self, packet)
Send a packet to the server.
source code
 
receive_packet(self, packet_type=None, timeout=SERVER_TIMEOUT)
Return the first received packet.
source code
 
_receive_event(self, timeout=SERVER_TIMEOUT)
Receives next event of type NONE or RECEIVE.
source code
 
_receive(self, timeout=SERVER_TIMEOUT)
Receive event and return unpacked packet.
source code
 
_reset(self) source code
Class Variables [hide private]
  log = logging.getLogger("network")
Method Details [hide private]

is_connected(self)

source code 
Decorators:
  • @property

connect(self)

source code 

Connect to master server.

After this, you can use `send_packet` and `receive_packet` to communicate with the server.

disconnect(self, server_may_disconnect=False)

source code 

End connection to master server.

This function should _never_ throw an exception.

ping(self)

source code 

Handle incoming packets.

Enet doesn't need to send pings. Call this regularly. Incoming packets can be handled by process_async_packet, otherwise will be added to a queue.

send_packet(self, packet)

source code 

Send a packet to the server.

packet has to be a subclass of `horizons.network.packets.packet`.

receive_packet(self, packet_type=None, timeout=SERVER_TIMEOUT)

source code 

Return the first received packet.

If packet_type is given, only a packet of that type will be returned.