Pyjo.IOLoop.Client - Non-blocking TCP/UDP client

import Pyjo.IOLoop.Client

# Create socket connection
with Pyjo.IOLoop.Client.new() as client:

    @client.on
    def connect(client, handle):
        ...

    @client.on
    def error(client, err):
        ...

    client.connect(address='example.com', port=80, proto='tcp')

    # Start reactor if necessary
    if not client.reactor.is_running:
        client.reactor.start()

Pyjo.IOLoop.Client opens TCP/UDP connections for Pyjo.IOLoop.

Events

Pyjo.IOLoop.Client inherits all events from Pyjo.EventEmitter and can emit the following new ones.

connect

@client.on
def connect(client, handle):
    ...

Emitted once the connection is established.

error

@client.on
def error(client, err):
    ...

Emitted if an error occurs on the connection, fatal if unhandled.

Classes

class Pyjo.IOLoop.Client.Pyjo_IOLoop_Client(*args, **kwargs)

Pyjo.IOLoop.Client inherits all attributes and methods from Pyjo.EventEmitter and implements the following new ones.

close()
client.close()

Close all server connections and server itself. Used by context manager.

connect(**kwargs)
client.connect(address='127.0.0.1', port=3000)

Open a socket connection to a remote host.

These options are currently available:

address
address='mojolicio.us'

Address or host name of the peer to connect to, defaults to 127.0.0.1.

handle
handle=handle

Use an already prepared handle.

local_address
local_address='127.0.0.1'

Local address to bind to.

port
port=80

Port to connect to, defaults to 80 or 443 with tls option.

proto
proto='tcp'

Transport protocol: tcp or udp, defaults to tcp.

timeout
timeout=15

Maximum amount of time in seconds establishing connection may take before getting canceled, defaults to 10.

tls
tls=True

Enable TLS.

tls_ca
tls_ca='/etc/ssl/certs/ca-certificates.crt'

Path to TLS certificate authority file. Also activates hostname verification.

tls_cert
tls_cert='/etc/ssl/certs/ssl-cert-snakeoil.pem'

Path to the TLS certificate file.

tls_key
tls_key='/etc/ssl/private/ssl-cert-snakeoil.key'

Path to the TLS key file.

fd
fd = stream.fd

Number of descriptor for handle

handle = None
handle = stream.handle

Handle for stream.

reactor = None
reactor = client.reactor
client.reactor = Pyjo.Reactor.Poll.new()

Low-level event reactor, defaults to the reactor attribute value of the global Pyjo.IOLoop singleton.

Pyjo.IOLoop.Client.object

alias of Pyjo_IOLoop_Client