Pyjo.IOLoop.Server - Non-blocking TCP server

import Pyjo.IOLoop.Server

# Create listen socket
with Pyjo.IOLoop.Server.new() as server:

    @server.on
    def accept(server, handle):
        ...

    server.listen(port=3000)

    # Start and stop accepting connections
    server.start()
    server.stop()

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

Pyjo.IOLoop.Server accepts TCP connections for Pyjo.IOLoop.

Events

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

accept

@server.on
def accept(server, handle):
    ...

Emitted for each accepted connection.

Classes

class Pyjo.IOLoop.Server.Pyjo_IOLoop_Server(*args, **kwargs)

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

close()
server.close()

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

fd
fd = stream.fd

Number of descriptor for handle

classmethod generate_port()
port = server.generate_port()

Find a free TCP port, primarily used for tests.

handle = None
handle = stream.handle

Handle for socket.

listen(**kwargs)
server.listen(port=3000)

Create a new listen socket.

These options are currently available:

address
address='127.0.0.1'

Local address to listen on, defaults to 0.0.0.0.

backlog
backlog=128

Maximum backlog size, defaults to socket.SOMAXCONN.

port
port=80

Port to listen on, defaults to a random port.

reuse
reuse=True

Allow multiple servers to use the same port with the socket.SO_REUSEPORT socket option.

tls
tls=True

Enable TLS.

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

Path to TLS certificate authority file.

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

Path to the TLS cert file, defaults to a built-in test certificate.

tls_ciphers
tls_ciphers='AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH'

Cipher specification string.

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

Path to the TLS key file, defaults to a built-in test key.

tls_verify
tls_verify=0x00

TLS verification mode, defaults to 0x03.

multi_accept = None
multi = server.multi_accept
server.multi_accept = 100

Number of connections to accept at once, defaults to 50.

port
port = server.port

Get port this server is listening on.

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

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

start()
server.start()

Start accepting connections.

stop()
server.stop()

Stop accepting connections.

Pyjo.IOLoop.Server.object

alias of Pyjo_IOLoop_Server