IPDaemon Class
Properties Methods Events Configuration Settings Errors
The IPDaemon Class is a generic TCP server class based on an asynchronous, event-driven architecture. It is designed to balance the load between connections for a fast, powerful server.
Syntax
class ipworks.IPDaemon
Remarks
The IPDaemon Class supports both plaintext and SSL/TLS connections. When connecting over SSL/TLS the on_ssl_server_authentication event allows you to check the server identity and other security attributes. The on_ssl_status event provides information about the SSL handshake. Additional SSL related settings are also supported via the config method. The SSLCert properties are used to select a certificate for the server (please note that a valid certificate MUST be selected before the server can function).
IPDaemon is the server complement of IPPort (which is used to create client applications). They share a common design philosophy and interface. We expect you will find IPDaemon as easy to use as IPPort.
By default, each instance of IPDaemon can handle up to 1,000 simultaneous incoming connections (this number may be increased up to 100,000 or decreased to a lower value by using the MaxConnections configuration setting).
The connections are identified by a ConnectionId, an id generated by the component to identify each connection. This id is unique to each connection. IPDaemon's events also have ConnectionId as a parameter to identify the connection they relate to.
Our main goal in designing IPDaemon was to make it easy to use without sacrificing performance. The class has a minimum of properties, and six events: on_connection_request, on_connected, on_data_in, on_disconnected, on_ready_to_send, and on_error.
IPDaemon can start to listen on a port by setting the listening property to True. When a remote host asks for a connection, the on_connection_request event is fired. At that point, the connection can either be accepted or rejected. If the connection is accepted, a ConnectionId is assigned, and communication can start. From this point on, the operation is very similar to IPPort. Data is sent by assigning the data string to the data_to_send property. The address and port of the incoming connection can be found by querying the remote_host and remote_port properties.
Note: Server components are designed to process events as they occur. To ensure events are processed in a timely manner do_events should be called in a loop after the server is started.
Property List
The following is the full list of the properties of the class with short descriptions. Click on the links for further details.
connection_backlog | The maximum number of pending connections maintained by the TCP/IP subsystem. |
connection_count | The number of records in the arrays. |
accept_data | Setting this property to False, temporarily disables data reception (and the DataIn event) on the connection. |
bytes_sent | This property shows how many bytes were sent after the last assignment to DataToSend . |
connected | This property is used to disconnect individual connections and/or show their status. |
connection_id | This property contains an identifier generated by the class to identify each connection. |
data_to_send | This property contains a string of data to be sent to the remote host. |
eol | The EOL property is used to define boundaries in the input stream using the value of the property. |
idle_timeout | The idle timeout for this connection. |
local_address | This property shows the IP address of the interface through which the connection is passing. |
ready_to_send | Indicates whether the class is ready to send data. |
record_length | If set to a positive value, this setting defines the length of data records to be received. |
remote_host | This property shows the IP address of the remote host through which the connection is coming. |
remote_port | This property shows the TCP port on the remote host through which the connection is coming. |
single_line_mode | This property shows the special mode for line-oriented protocols. |
timeout | This property specifies a timeout for the class. |
user_data | The UserData property holds connection specific user specified data. |
default_eol | A default EOL value to be used by incoming connections. |
default_idle_timeout | The default idle timeout for inactive clients. |
default_max_line_length | The default maximum line length value for inbound connections. |
default_single_line_mode | Tells the class whether or not to treat new connections as line-oriented. |
default_timeout | An initial timeout value to be used by incoming connections. |
keep_alive | When True, KEEPALIVE packets are enabled (for long connections). |
linger | When set to True, connections are terminated gracefully. |
listening | If True, the class accepts incoming connections on LocalPort. |
local_host | The name of the local host or user-assigned IP interface through which connections are initiated or accepted. |
local_port | The TCP port in the local host where the class listens. |
ssl_authenticate_clients | If true, the server asks the client(s) for a certificate. |
ssl_cert_encoded | The certificate (PEM/base64 encoded). |
ssl_cert_store | The name of the certificate store for the client certificate. |
ssl_cert_store_password | If the certificate store is of a type that requires a password, this property is used to specify that password in order to open the certificate store. |
ssl_cert_store_type | The type of certificate store for this certificate. |
ssl_cert_subject | The subject of the certificate used for client authentication. |
ssl_enabled | Whether TLS/SSL is enabled. |
ssl_start_mode | Determines how the class starts the SSL negotiation. |
Method List
The following is the full list of the methods of the class with short descriptions. Click on the links for further details.
config | Sets or retrieves a configuration setting. |
disconnect | Disconnect the specified client. |
do_events | Processes events from the internal message queue. |
interrupt | Interrupts a synchronous send to the remote host. |
reset | Reset the class. |
send | Sends data to the remote host. |
send_file | Send file to the remote host. |
send_line | Sends a string followed by a newline. |
shutdown | Shuts down the server. |
start_ssl | Starts SSL negotiation on a connection. |
Event List
The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.
on_connected | Fired immediately after a connection completes (or fails). |
on_connection_request | Fired when a request for connection comes from a remote host. |
on_data_in | Fired when data comes in. |
on_disconnected | Fired when a connection is closed. |
on_error | Information about errors during data delivery. |
on_ready_to_send | Fired when the class is ready to send data. |
on_ssl_client_authentication | Fired when the client presents its credentials to the server. |
on_ssl_connection_request | Fires when an SSL connection is requested. |
on_ssl_status | Shows the progress of the secure connection. |
Configuration Settings
The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.
AllowedClients | A comma-separated list of host names or IP addresses that can access the class. |
BindExclusively | Whether or not the class considers a local port reserved for exclusive use. |
ConnectionUID | The unique connectionId for a connection. |
DefaultConnectionTimeout | The inactivity timeout applied to the SSL handshake. |
InBufferSize | The size in bytes of the incoming queue of the socket. |
KeepAliveInterval | The retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received. |
KeepAliveRetryCount | The number of keep-alive packets to be sent before the remotehost is considered disconnected. |
KeepAliveTime | The inactivity time in milliseconds before a TCP keep-alive packet is sent. |
MaxConnections | The maximum number of connections available. |
OutBufferSize | The size in bytes of the outgoing queue of the socket. |
TcpNoDelay | Whether or not to delay when sending packets. |
UseIOCP | Whether to use the completion port I/O model. |
UseIPv6 | Whether to use IPv6. |
UseWindowsMessages | Whether to use the WSAAsyncSelect I/O model. |
LogSSLPackets | Controls whether SSL packets are logged when using the internal security API. |
OpenSSLCADir | The path to a directory containing CA certificates. |
OpenSSLCAFile | Name of the file containing the list of CA's trusted by your application. |
OpenSSLCipherList | A string that controls the ciphers to be used by SSL. |
OpenSSLPrngSeedData | The data to seed the pseudo random number generator (PRNG). |
ReuseSSLSession | Determines if the SSL session is reused. |
SSLCACertFilePaths | The paths to CA certificate files on Unix/Linux. |
SSLCACerts | A newline separated list of CA certificate to use during SSL client authentication. |
SSLCheckCRL | Whether to check the Certificate Revocation List for the server certificate. |
SSLCipherStrength | The minimum cipher strength used for bulk encryption. |
SSLEnabledCipherSuites | The cipher suite to be used in an SSL negotiation. |
SSLEnabledProtocols | Used to enable/disable the supported security protocols. |
SSLEnableRenegotiation | Whether the renegotiation_info SSL extension is supported. |
SSLIncludeCertChain | Whether the entire certificate chain is included in the SSLServerAuthentication event. |
SSLNegotiatedCipher | Returns the negotiated ciphersuite. |
SSLNegotiatedCipherStrength | Returns the negotiated ciphersuite strength. |
SSLNegotiatedCipherSuite | Returns the negotiated ciphersuite. |
SSLNegotiatedKeyExchange | Returns the negotiated key exchange algorithm. |
SSLNegotiatedKeyExchangeStrength | Returns the negotiated key exchange algorithm strength. |
SSLNegotiatedVersion | Returns the negotiated protocol version. |
SSLProvider | The name of the security provider to use. |
SSLSecurityFlags | Flags that control certificate verification. |
SSLServerCACerts | A newline separated list of CA certificate to use during SSL server certificate validation. |
TLS12SignatureAlgorithms | Defines the allowed TLS 1.2 signature algorithms when UseInternalSecurityAPI is True. |
TLS12SupportedGroups | The supported groups for ECC. |
TLS13KeyShareGroups | The groups for which to pregenerate key shares. |
TLS13SignatureAlgorithms | The allowed certificate signature algorithms. |
TLS13SupportedGroups | The supported groups for (EC)DHE key exchange. |
BuildInfo | Information about the product's build. |
CodePage | The system code page used for Unicode to Multibyte translations. |
LicenseInfo | Information about the current license. |
ProcessIdleEvents | Whether the class uses its internal event loop to process events when the main thread is idle. |
SelectWaitMillis | The length of time in milliseconds the class will wait when DoEvents is called if there are no events to process. |
UseInternalSecurityAPI | Tells the class whether or not to use the system security libraries or an internal implementation. |