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 Base Class for Server. |
|
Nonblocking TCP Socket Server Class. |
|
Server with Nonblocking TLS/SSL support |
|
Class to service an incoming nonblocking TCP connection from a remote client. |
|
Class to service an incoming nonblocking TCP/TLS connection from a remote client. |
|
Basic TCP Server Doer |
|
Echo TCP Server |
Functions
|
Wrapper to create and open TCP Server instances |
|
Initialize and return context for TLS Server |
Attributes
- 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.TymeeAcceptor 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’)
- class hio.core.tcp.serving.Server(ha=None, host='', port=56000, tymeout=None, wl=None, **kwa)[source]
Bases:
AcceptorNonblocking 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
- 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
- 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:
ServerServer 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
- class hio.core.tcp.serving.Remoter(ha, ca, cs, tymeout=None, refreshable=True, bs=8096, wl=None, **kwa)[source]
Bases:
hio.base.tyming.TymeeClass to service an incoming nonblocking TCP connection from a remote client. Should only be used from Acceptor subclass
- wind(self, tymth)[source]
Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth
- 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
- class hio.core.tcp.serving.RemoterTls(context=None, version=None, certify=None, keypath=None, certpath=None, cafilepath=None, **kwa)[source]
Bases:
RemoterClass to service an incoming nonblocking TCP/TLS connection from a remote client. Should only be used from Acceptor subclass Provides nonblocking TLS/SSL support
- 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
- class hio.core.tcp.serving.ServerDoer(server, **kwa)[source]
Bases:
hio.base.doing.DoerBasic TCP Server Doer
See Doer for inherited attributes, properties, and methods.
- .server is TCP Server instance
Properties:
- class hio.core.tcp.serving.EchoServerDoer(server, **kwa)[source]
Bases:
ServerDoerEcho 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