panda3d.core.ConnectionManager

from panda3d.core import ConnectionManager
class ConnectionManager

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
__init__(param0: Interface) → None
getBroadcast() → NetAddress
Return type

NetAddress

getIp() → NetAddress
Return type

NetAddress

getMacAddress() → str
getName() → str
getNetmask() → NetAddress
Return type

NetAddress

getP2p() → NetAddress
Return type

NetAddress

hasBroadcast() → bool
hasIp() → bool
hasNetmask() → bool
hasP2p() → bool
output(out: ostream) → None
__init__() → None
closeConnection(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 closeConnection() 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 getHostName() → str

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

getInterface(n: size_t) → Interface

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

Return type

Interface

getInterfaces() → list
getNumInterfaces() → size_t

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

Return type

size_t

property host_name

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

Return type

string

property interfaces

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

Return type

Sequence[Interface]

openTCPClientConnection(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.

Return type

Connection

openTCPClientConnection(hostname: str, port: uint16_t, timeout_ms: int) → Connection

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

Return type

Connection

openTCPServerRendezvous(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.

Return type

Connection

openTCPServerRendezvous(hostname: str, port: uint16_t, 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.

Return type

Connection

openTCPServerRendezvous(port: uint16_t, 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.

Return type

Connection

openUDPConnection(hostname: str, port: uint16_t, 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.

Return type

Connection

openUDPConnection(port: uint16_t) → 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.

Return type

Connection

scanInterfaces() → None

Repopulates the list reported by get_num_interface()/getInterface(). 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).

waitForReaders(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.