XMPP Connection¶
Events¶
tcp_established | the TCP connection was established |
tcp_restablished | the TCP connection was lost and restablished |
tcp_downgraded | the TLS connection was downgraded to TCP |
tcp_disconnect | the TCP connection was lost |
tcp_failed | the TCP connection failed to be established |
tls_established | the TLS connection was established |
tls_invalid_chain | the TLS handshake failed for invalid chain |
tls_invalid_cert | the TLS handshake failed for invalid server cert |
tls_failed | failed to establish a TLS connection |
tls_start | started SSL negotiation |
write | the TCP/TLS connection has sent data |
read | the TCP/TLS connection has received data |
ready_to_write | the TCP/TLS connection is ready to send data |
ready_to_read | the TCP/TLS connection is ready to receive data |
API¶
-
class
xmpp.networking.core.
XMPPConnection
(host, port=5222, debug=False, auto_reconnect=False, queue_class=<class Queue.Queue>, hwm_in=256, hwm_out=256, recv_chunk_size=65536)[source]¶ Event-based TCP/TLS connection.
It buffers up received messages and also the messages to be sent.
Parameters: - host – a string containing a domain or ip address. If a domain is given the name will be resolved before connecting.
- port – defaults to
5222
. If you are using a component you might point to5347
or something else. - debug –
bool
defaults toFalse
: whether to print the XML traffic on stderr - queue_class –
bool
defaults to :py:class`Queue.Queue` - hwm_in –
int
defaults to 256: how many incomming messages to buffer before blocking - hwm_out –
int
defaults to 256: how many outcomming messages to buffer before blocking - recv_chunk_size –
int
defaults to65536
: how many bytes to read at a time.
-
disconnect
()[source]¶ disconencts the socket
published events:
tcp_disconnect("intentional")
- when succeeded
Parameters: timeout_in_seconds –
-
loop_once
(timeout=3)[source]¶ entrypoint for any mainloop.
basically call this continuously to keep the connection up
-
perform_read
(connection)[source]¶ reads from the socket and populates the read queue :param connection: a socket that is ready to write
-
perform_write
(connection)[source]¶ consumes the write queue and writes to the given socket
Parameters: connection – a socket that is ready to write
-
receive
(timeout=3)[source]¶ retrieves a message from the queue, returns
None
if there are no messages.Parameters: timeout – int
in seconds
-
reconnect
(timeout_in_seconds=3)[source]¶ reconnects the socket
published events:
tcp_restablished(host)
- when succeededtcp_failed(host)
- when failed
Parameters: timeout_in_seconds –
-
send
(data, timeout=3)[source]¶ adds bytes to the be sent in the next time the socket is ready
Parameters: - data – the data to be sent
- timeout –
int
in seconds
-
send_whitespace_keepalive
(timeout=3)[source]¶ sends a whitespace keepalive to avoid connection timeouts and dead connections
published events:
tcp_disconnect("intentional")
- when succeeded
Parameters: timeout_in_seconds –