ConnectionManager

from panda3d.core import ConnectionManager
class ConnectionManager

Bases:

The primary interface to the low-level networking layer in this package. A ConnectionManager is used to establish and destroy TCP and UDP connections. Communication on these connections, once established, is handled via ConnectionReader, ConnectionWriter, and ConnectionListener.

You may use this class directly if you don’t care about tracking which connections have been unexpectedly closed; otherwise, you should use QueuedConnectionManager to get reports about these events (or derive your own class to handle these events properly).

Inheritance diagram

Inheritance diagram of ConnectionManager

class Interface

Bases:

__init__(param0: Interface)
get_broadcast() NetAddress
get_ip() NetAddress
get_mac_address() str
get_name() str
get_netmask() NetAddress
get_p2p() NetAddress
has_broadcast() bool
has_ip() bool
has_netmask() bool
has_p2p() bool
output(out: ostream)
__init__()
close_connection(connection: Connection) bool

Terminates a UDP or TCP socket previously opened. This also removes it from any associated ConnectionReader or ConnectionListeners.

The socket itself may not be immediately closed–it will not be closed until all outstanding pointers to it are cleared, including any pointers remaining in NetDatagrams recently received from the socket.

The return value is true if the connection was marked to be closed, or false if close_connection() had already been called (or the connection did not belong to this ConnectionManager). In neither case can you infer anything about whether the connection has actually been closed yet based on the return value.

static get_host_name() str

Returns the name of this particular machine on the network, if available, or the empty string if the hostname cannot be determined.

get_interface(n: int) Interface

Returns the nth usable network interface detected on this machine. See scan_interfaces() to repopulate this list.

get_interfaces() list
get_num_interfaces() int

This returns the number of usable network interfaces detected on this machine. See scan_interfaces() to repopulate this list.

property host_name string

Returns the name of this particular machine on the network, if available, or the empty string if the hostname cannot be determined.

property interfaces Sequence[Interface]

Returns the nth usable network interface detected on this machine. See scan_interfaces() to repopulate this list.

open_TCP_client_connection(address: NetAddress, timeout_ms: int) Connection

Attempts to establish a TCP client connection to a server at the indicated address. If the connection is not established within timeout_ms milliseconds, a null connection is returned.

open_TCP_client_connection(hostname: str, port: int, timeout_ms: int) Connection

This is a shorthand version of the function to directly establish communications to a named host and port.

open_TCP_server_rendezvous(address: NetAddress, backlog: int) Connection

Creates a socket to be used as a rendezvous socket for a server to listen for TCP connections. The socket returned by this call should only be added to a ConnectionListener (not to a generic ConnectionReader).

This variant of this method accepts a NetAddress, which allows you to specify a specific interface to listen to.

backlog is the maximum length of the queue of pending connections.

open_TCP_server_rendezvous(hostname: str, port: int, backlog: int) Connection

Creates a socket to be used as a rendezvous socket for a server to listen for TCP connections. The socket returned by this call should only be added to a ConnectionListener (not to a generic ConnectionReader).

This variant of this method accepts a “hostname”, which is usually just an IP address in dotted notation, and a port number. It will listen on the interface indicated by the IP address. If the IP address is empty string, it will listen on all interfaces.

backlog is the maximum length of the queue of pending connections.

open_TCP_server_rendezvous(port: int, backlog: int) Connection

Creates a socket to be used as a rendezvous socket for a server to listen for TCP connections. The socket returned by this call should only be added to a ConnectionListener (not to a generic ConnectionReader).

This variant of this method accepts a single port, and will listen to that port on all available interfaces, both IPv4 and IPv6.

backlog is the maximum length of the queue of pending connections.

open_UDP_connection(hostname: str, port: int, for_broadcast: bool) Connection

Opens a socket for sending and/or receiving UDP packets. If the port number is greater than zero, the UDP connection will be opened for listening on the indicated port; otherwise, it will be useful only for sending.

This variant accepts both a hostname and port to listen on a particular interface; if the hostname is empty, all interfaces will be available, both IPv4 and IPv6.

If for_broadcast is true, this UDP connection will be configured to send and/or receive messages on the broadcast address (255.255.255.255); otherwise, these messages may be automatically filtered by the OS.

Use a ConnectionReader and ConnectionWriter to handle the actual communication.

open_UDP_connection(port: int) Connection

Opens a socket for sending and/or receiving UDP packets. If the port number is greater than zero, the UDP connection will be opened for listening on the indicated port; otherwise, it will be useful only for sending.

Use a ConnectionReader and ConnectionWriter to handle the actual communication.

scan_interfaces()

Repopulates the list reported by get_num_interface()/get_interface(). It is not necessary to call this explicitly, unless you want to re-determine the connected interfaces (for instance, if you suspect the hardware has recently changed).

wait_for_readers(timeout: float) bool

Blocks the process for timeout number of seconds, or until any data is available on any of the non-threaded ConnectionReaders or ConnectionListeners, whichever comes first. The return value is true if there is data available (but you have to iterate through all readers to find it), or false if the timeout occurred without any data.

If the timeout value is negative, this will block forever or until data is available.

This only works if all ConnectionReaders and ConnectionListeners are non- threaded. If any threaded ConnectionReaders are part of the ConnectionManager, the timeout value is implicitly treated as 0.