Panda3D
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
ConnectionManager Class Reference

The primary interface to the low-level networking layer in this package. More...

Inheritance diagram for ConnectionManager:
QueuedConnectionManager

Classes

class  Interface
 

Public Member Functions

 __init__ ()
 
bool closeConnection (Connection connection)
 Terminates a UDP or TCP socket previously opened. More...
 
const ConnectionManager::Interface getInterface (int n)
 Returns the nth usable network interface detected on this machine. More...
 
list getInterfaces ()
 
int getNumInterfaces ()
 This returns the number of usable network interfaces detected on this machine. More...
 
Connection openTCPClientConnection (const NetAddress address, int timeout_ms)
 Attempts to establish a TCP client connection to a server at the indicated address. More...
 
Connection openTCPClientConnection (str hostname, uint16_t port, int timeout_ms)
 This is a shorthand version of the function to directly establish communications to a named host and port. More...
 
Connection openTCPServerRendezvous (const NetAddress address, int backlog)
 Creates a socket to be used as a rendezvous socket for a server to listen for TCP connections. More...
 
Connection openTCPServerRendezvous (str hostname, uint16_t port, int backlog)
 Creates a socket to be used as a rendezvous socket for a server to listen for TCP connections. More...
 
Connection openTCPServerRendezvous (uint16_t port, int backlog)
 Creates a socket to be used as a rendezvous socket for a server to listen for TCP connections. More...
 
Connection openUDPConnection (str hostname, uint16_t port, bool for_broadcast)
 Opens a socket for sending and/or receiving UDP packets. More...
 
Connection openUDPConnection (uint16_t port)
 Opens a socket for sending and/or receiving UDP packets. More...
 
 scanInterfaces ()
 Repopulates the list reported by get_num_interface()/get_interface(). More...
 
bool waitForReaders (double timeout)
 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. More...
 

Static Public Member Functions

static str getHostName ()
 Returns the name of this particular machine on the network, if available, or the empty string if the hostname cannot be determined. More...
 

Public Attributes

String host_name
 Returns the name of this particular machine on the network, if available, or the empty string if the hostname cannot be determined. More...
 
const ConnectionManager::Interface interfaces []
 

Detailed Description

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).

Member Function Documentation

◆ __init__()

__init__ ( )

◆ closeConnection()

bool closeConnection ( Connection  connection)

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.

◆ getHostName()

static str getHostName ( )
static

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

◆ getInterface()

const ConnectionManager::Interface getInterface ( int  n)

Returns the nth usable network interface detected on this machine.

See scan_interfaces() to repopulate this list.

◆ getInterfaces()

list getInterfaces ( )

◆ getNumInterfaces()

int getNumInterfaces ( )

This returns the number of usable network interfaces detected on this machine.

See scan_interfaces() to repopulate this list.

◆ openTCPClientConnection() [1/2]

Connection openTCPClientConnection ( const NetAddress  address,
int  timeout_ms 
)

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.

◆ openTCPClientConnection() [2/2]

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

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

◆ openTCPServerRendezvous() [1/3]

Connection openTCPServerRendezvous ( const NetAddress  address,
int  backlog 
)

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.

◆ openTCPServerRendezvous() [2/3]

Connection openTCPServerRendezvous ( str  hostname,
uint16_t  port,
int  backlog 
)

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.

◆ openTCPServerRendezvous() [3/3]

Connection openTCPServerRendezvous ( uint16_t  port,
int  backlog 
)

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.

◆ openUDPConnection() [1/2]

Connection openUDPConnection ( str  hostname,
uint16_t  port,
bool  for_broadcast 
)

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.

◆ openUDPConnection() [2/2]

Connection openUDPConnection ( uint16_t  port)

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.

◆ scanInterfaces()

scanInterfaces ( )

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).

◆ waitForReaders()

bool waitForReaders ( double  timeout)

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.

Member Data Documentation

◆ host_name

String host_name

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

◆ interfaces

const ConnectionManager::Interface interfaces[]