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 to 5347 or something else.
  • debugbool defaults to False: whether to print the XML traffic on stderr
  • queue_classbool defaults to :py:class`Queue.Queue`
  • hwm_inint defaults to 256: how many incomming messages to buffer before blocking
  • hwm_outint defaults to 256: how many outcomming messages to buffer before blocking
  • recv_chunk_sizeint defaults to 65536: how many bytes to read at a time.
connect(timeout_in_seconds=3)[source]

connects

Parameters:timeout_in_seconds
disconnect()[source]

disconencts the socket

published events:

  • tcp_disconnect("intentional") - when succeeded
Parameters:timeout_in_seconds
is_alive()[source]
Returns:True if the connection is alive
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:timeoutint in seconds
reconnect(timeout_in_seconds=3)[source]

reconnects the socket

published events:

  • tcp_restablished(host) - when succeeded
  • tcp_failed(host) - when failed
Parameters:timeout_in_seconds
resolve_dns()[source]

resolves the given host

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
  • timeoutint 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