hio.core.tcp.serving

hio.core.tcp.serving Module

Accepter listens and accepts incoming TCP socket connections Server is subclass of Acceptor Server creates Remoters Remoter is accepted incoming socket connection

ServerTls is subclass of Server RemoterTls is subclass of Remoter

Module Contents

Classes

Acceptor

Acceptor Base Class for Server.

Server

Nonblocking TCP Socket Server Class.

ServerTls

Server with Nonblocking TLS/SSL support

Remoter

Class to service an incoming nonblocking TCP connection from a remote client.

RemoterTls

Class to service an incoming nonblocking TCP/TLS connection from a remote client.

ServerDoer

Basic TCP Server Doer

EchoServerDoer

Echo TCP Server

Functions

openServer(cls=None, **kwa)

Wrapper to create and open TCP Server instances

initServerContext(context=None, version=None, certify=None, keypath=None, certpath=None, cafilepath=None)

Initialize and return context for TLS Server

Attributes

logger

hio.core.tcp.serving.logger[source]
hio.core.tcp.serving.openServer(cls=None, **kwa)[source]

Wrapper to create and open TCP Server instances When used in with statement block, calls .close() on exit of with block

Parameters

instance (cls is Class instance of subclass) –

Usage:
with openServer() as server0:

server0.

with openServer(cls=ServerTls) as server0:

server0.

class hio.core.tcp.serving.Acceptor(ha=None, bs=8096, **kwa)[source]

Bases: hio.base.tyming.Tymee

Acceptor Base Class for Server. Nonblocking TCP Socket Acceptor Class. Listen socket for incoming TCP connections

See tyming.Tymee for inherited attributes, properties, and methods

.ha is

host = “” or “0.0.0.0” means listen on all interfaces

Type

host,port) duple (two tuple

.eha is normalized

as external facing address for TLS context

Type

host, port

.bs is buffer size
.ss is server listen socket for incoming accept requests
.axes is deque of accepte connection duples
Type

ca, cs

.opened is boolean, True if listen socket .ss opened. False otherwise
actualBufSizes(self)[source]

Returns duple of the the actual socket send and receive buffer size (send, receive)

open(self)[source]

Opens binds listen socket in non blocking mode.

if socket not closed properly, binding socket gets error

OSError: (48, ‘Address already in use’)

reopen(self)[source]

Idempotently opens listen socket

close(self)[source]

Closes listen socket.

accept(self)[source]

Accept new connection nonblocking Returns duple (cs, ca) of connected socket and connected host address Otherwise if no new connection returns (None, None)

serviceAccepts(self)[source]

Service any accept requests Adds to .cxes dict key by ca

class hio.core.tcp.serving.Server(ha=None, host='', port=56000, tymeout=None, wl=None, **kwa)[source]

Bases: Acceptor

Nonblocking TCP Socket Server Class. Listen socket for incoming TCP connections that generates Remoter sockets for accepted connections

See tyming.Tymee for inherited attributes, properties, and methods

Inherited Attributes:
.ha is (host,port) duple (two tuple)

host = “” or “0.0.0.0” means listen on all interfaces

.eha is normalized (host, port) duple for incoming TLS connections

as external facing address for TLS context

.bs is buffer size .ss is server listen socket for incoming accept requests .axes is deque of accepte connection duples (ca, cs) .opened is boolean, True if listen socket .ss opened. False otherwise

.tymeout is tymeout in seconds for connection refresh
.wl is WireLog instance if any
.ixes is dict of incoming connections indexed by remote
Type

host, port

Tymeout = 1.0[source]
wind(self, tymth)[source]

Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth

serviceAxes(self)[source]

Service axes

For each newly accepted connection in .axes create Remoter and add to .ixes keyed by ca

serviceConnects(self)[source]

Service connects is method name to be used

shutdownIx(self, ca, how=socket.SHUT_RDWR)[source]

Shutdown remoter given by connection address ca

shutdownSendIx(self, ca)[source]

Shutdown send on remoter given by connection address ca

shutdownReceiveIx(self, ca)[source]

Shutdown send on remoter given by connection address ca

closeIx(self, ca)[source]

Shutdown and close remoter given by connection address ca

closeAllIx(self)[source]

Shutdown and close all remoter connections

close(self)[source]

Close all sockets

removeIx(self, ca, close=True)[source]

Remove remoter given by connection address ca

serviceReceivesIx(self, ca)[source]

Service receives for remoter by connection address ca

serviceReceivesAllIx(self)[source]

Service receives for all remoters in .ixes

transmitIx(self, data, ca)[source]

Queue data onto .txbs for remoter given by connection address ca

serviceSendsAllIx(self)[source]

Service transmits for all remoters in .ixes

service(self)[source]

Service connects and service receives and sends for all ix.

hio.core.tcp.serving.initServerContext(context=None, version=None, certify=None, keypath=None, certpath=None, cafilepath=None)[source]

Initialize and return context for TLS Server IF context is None THEN create a context

IF version is None THEN create context using ssl library default ELSE create context with version

If certify is not None then use certify value provided Otherwise use default

context = context object for tls/ssl If None use default version = ssl protocol version If None use default certify = cert requirement If None use default

ssl.CERT_NONE = 0 ssl.CERT_OPTIONAL = 1 ssl.CERT_REQUIRED = 2

keypath = pathname of local server side PKI private key file path

If given apply to context

certpath = pathname of local server side PKI public cert file path

If given apply to context

cafilepath = Cert Authority file path to use to verify client cert

If given apply to context

class hio.core.tcp.serving.ServerTls(context=None, version=None, certify=None, keypath=None, certpath=None, cafilepath=None, **kwa)[source]

Bases: Server

Server with Nonblocking TLS/SSL support Nonblocking TCP Socket Server Class. Listen socket for incoming TCP connections RemoterTLS sockets for accepted connections

See tyming.Tymee for inherited attributes, properties, and methods

Inherited Attributes:
.ha is (host,port) duple (two tuple)

host = “” or “0.0.0.0” means listen on all interfaces

.eha is normalized (host, port) duple for incoming TLS connections

as external facing address for TLS context

.bs is buffer size .ss is server listen socket for incoming accept requests .axes is deque of accepte connection duples (ca, cs) .opened is boolean, True if listen socket .ss opened. False otherwise .timeout is timeout in seconds for connection refresh .wl is WireLog instance if any .ixes is dict of incoming connections indexed by remote (host, port) duple

.context is TLS context instance
.version is TLS version
.certify is boolean, True to client certify, False otherwise
.keypath is path to key file
.certpath is path to cert file
.cafilepath is path to ca file
serviceAxes(self)[source]

Service accepteds

For each new accepted connection create RemoterTLS and add to .cxes Not Handshaked

serviceCxes(self)[source]

Service handshakes for every remoter in .cxes If successful move to .ixes

serviceConnects(self)[source]

Service accept and handshake attempts If not already accepted and handshaked Then

make nonblocking attempt

For each successful handshaked add to .ixes Returns handshakeds

class hio.core.tcp.serving.Remoter(ha, ca, cs, tymeout=None, refreshable=True, bs=8096, wl=None, **kwa)[source]

Bases: hio.base.tyming.Tymee

Class to service an incoming nonblocking TCP connection from a remote client. Should only be used from Acceptor subclass

Tymeout = 0.0[source]
wind(self, tymth)[source]

Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth

shutdown(self, how=socket.SHUT_RDWR)[source]

Shutdown connected socket .cs

shutdownSend(self)[source]

Shutdown send on connected socket .cs

shutdownReceive(self)[source]

Shutdown receive on connected socket .cs

close(self)[source]

Shutdown and close connected socket .cs

refresh(self)[source]

Restart tymer

receive(self)[source]

Perform non blocking receive on connected socket .cs

If no data then returns None If connection closed then returns ‘’ Otherwise returns data

data is string in python2 and bytes in python3

serviceReceives(self)[source]

Service receives until no more

serviceReceiveOnce(self)[source]

Retrieve from server only one reception

clearRxbs(self)[source]

Clear .rxbs

send(self, data)[source]

Perform non blocking send on connected socket .cs. Return number of bytes sent

data is string in python2 and bytes in python3

tx(self, data)[source]

Queue data onto .txbs

serviceSends(self)[source]

Service transmits For each tx if all bytes sent then keep sending until partial send or no more to send If partial send reattach and return

class hio.core.tcp.serving.RemoterTls(context=None, version=None, certify=None, keypath=None, certpath=None, cafilepath=None, **kwa)[source]

Bases: Remoter

Class to service an incoming nonblocking TCP/TLS connection from a remote client. Should only be used from Acceptor subclass Provides nonblocking TLS/SSL support

close(self)[source]

Shutdown and close connected socket .cs

wrap(self)[source]

Wrap socket .cs in ssl context

handshake(self)[source]

Attempt nonblocking ssl handshake to .ha Returns True if successful Returns False if not so try again later

serviceHandshake(self)[source]

Service connection and handshake attempt If not already accepted and handshaked Then

make nonblocking attempt

Returns .handshaked

receive(self)[source]

Perform non blocking receive on connected socket .cs

If no data then returns None If connection closed then returns ‘’ Otherwise returns data

data is string in python2 and bytes in python3

send(self, data)[source]

Perform non blocking send on connected socket .cs. Return number of bytes sent

data is string in python2 and bytes in python3

class hio.core.tcp.serving.ServerDoer(server, **kwa)[source]

Bases: hio.base.doing.Doer

Basic TCP Server Doer

See Doer for inherited attributes, properties, and methods.

.server is TCP Server instance

Properties:

wind(self, tymth)[source]

Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth

enter(self)[source]
recur(self, tyme)[source]
exit(self)[source]
class hio.core.tcp.serving.EchoServerDoer(server, **kwa)[source]

Bases: ServerDoer

Echo TCP Server Just echoes back to client whatever it receives from client

See Doer for inherited attributes, properties, and methods.

Inherited Attributes:

.server is TCP Server instance

enter(self)[source]
recur(self, tyme)[source]
exit(self)[source]