hio.core.tcp package
Submodules
hio.core.tcp.clienting module
hio.core.tcp.clienting Module
- class hio.core.tcp.clienting.Client(tymeout=None, ha=None, host='127.0.0.1', port=56000, reconnectable=None, bs=8096, txbs=None, rxbs=None, wl=None, **kwa)
Bases:
TymeeNonblocking TCP Socket Client Class.
See tyming.Tymee for inherited attributes, properties, and methods
Attributes:
Properties:
Methods:
- Reconnectable = False
- Tymeout = 0.0
- __init__(tymeout=None, ha=None, host='127.0.0.1', port=56000, reconnectable=None, bs=8096, txbs=None, rxbs=None, wl=None, **kwa)
Initialization method for instance.
- Parameters:
of (tymth is injected function wrapper closure returned by .tymen()) – Tymist instance. Calling tymth() returns associated Tymist .tyme.
tymeout (tymeout = auto reconnect retry)
duple (ha = host address)
to (host = host address or tcp server to connect)
port (port = socket)
out (reconnectable = Boolean retry auto reconnect if timed)
size (bs = buffer)
send (txbs = bytearray of data to)
received (rxbs = bytearray of data)
any (wl = WireLog object if)
- accept()
Attempt nonblocking acceptance connect to .ha Returns True if successful Returns False if not so try again later
- property accepted
Property that returns accepted state of TCP socket
- actualBufSizes()
Returns duple of the the actual socket send and receive buffer size (send, receive)
- clearRxbs()
Clear .rxbs
- close()
Shutdown and close connected socket .cs
- connect()
Attempt nonblocking connect to .ha Returns True if successful Returns False if not so try again later For non-TLS tcp connect is done when accepted This is placeholder for subclass Tls
- property connected
Property that returns connected state of TCP socket Non-tls tcp is connected when accepted
- property host
Property that returns host in .ha duple
- open()
Opens connection socket in non blocking mode.
- if socket not closed properly, binding socket gets error
OSError: (48, ‘Address already in use’)
- property port
Property that returns port in .ha duple
- receive()
Perform non blocking receive from connected socket .cs
If no data then returns None If connection closed then returns empty Otherwise returns data data is string in python2 and bytes in python3
- refresh()
Restart timer
- reopen()
Idempotently opens socket
- send(data)
Perform non blocking send on connected socket .cs. Return number of bytes sent data is string in python2 and bytes in python3
- service()
Service connect, txbs, and receives.
- serviceConnect()
Service connection attempt If not already connected make a nonblocking attempt Returns .connected
- serviceReceiveOnce()
Retrieve from server only one reception
- serviceReceives()
Service receives until no more
- serviceSends()
Service sends (transmits) of data in .txbs bytearray Attempt to send all of .txbs. Delete what is actually sent.
- shutdown(how=2)
Shutdown connected socket .cs
- shutdownReceive()
Shutdown receive on connected socket .cs
- shutdownSend()
Shutdown send on connected socket .cs
- tx(data)
Copy data onto .txbs, .extend copies data.
- wind(tymth)
Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth
- class hio.core.tcp.clienting.ClientDoer(client, **kwa)
Bases:
DoerBasic TCP Client Doer
See Doer for inherited attributes, properties, and methods.
- .client is TCP Client instance
- __init__(client, **kwa)
Initialize instance.
- Parameters:
instance (client is TCP Client)
- enter(*, temp=None)
Do ‘enter’ context actions. Set up resources. Comparable to context manager enter.
- Parameters:
temp (bool | None) – True means use temporary file resources if any None means ignore parameter value. Use self.temp
Inject temp or self.temp into file resources here if any
- exit()
- recur(tyme)
- wind(tymth)
Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth
- class hio.core.tcp.clienting.ClientTls(context=None, version=None, certify=None, hostify=None, certedhost='', keypath=None, certpath=None, cafilepath=None, **kwa)
Bases:
ClientOutgoer with Nonblocking TLS/SSL support Nonblocking TCP Socket Client Class.
Attributes:
Properties:
Methods:
- __init__(context=None, version=None, certify=None, hostify=None, certedhost='', keypath=None, certpath=None, cafilepath=None, **kwa)
Initialization method for instance.
IF no context THEN create one IF no version THEN create using library default IF certify is not None then use certify else use default IF hostify is not none the use hostify else use default
- Parameters:
default (hostify = verify server hostName If None use)
default
default – ssl.CERT_NONE = 0 ssl.CERT_OPTIONAL = 1 ssl.CERT_REQUIRED = 2
path (certpath = pathname of local client side PKI public cert file) – If given apply to context
path – If given apply to context
cert (cafilepath = Cert Authority file path to use to verify server) – If given apply to context
default
name (certedhost = server's certificate common)
- close()
Shutdown and close connected socket .cs
- connect()
Attempt nonblocking connect to .ha Returns True if successful Returns False if not so try again later Connected when both accepted connection and TLS handshake complete
- property connected
Property that returns connected state of TCP socket TLS tcp is connected when accepted and handshake completed
- handshake()
Attempt nonblocking ssl handshake to .ha Returns True if successful Returns False if not so try again later
- receive()
Perform non blocking receive from 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(data)
Perform non blocking send on connected socket .cs. Return number of bytes sent data is string in python2 and bytes in python3
- wrap()
Wrap socket .cs in ssl context
- hio.core.tcp.clienting.openClient(cls=None, **kwa)
Wrapper to create and open TCP Client instances When used in with statement block, calls .close() on exit of with block
- Parameters:
instance (cls is Class instance of subclass)
Usage:
with openClient() as client0: client0.accept() with openClient(cls=ClientTls) as client0: client0.accept()
hio.core.tcp.serving module
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
- class hio.core.tcp.serving.Acceptor(ha=None, bs=8096, bl=128, **kwa)
Bases:
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
- .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
- __init__(ha=None, bs=8096, bl=128, **kwa)
Initialization method for instance. ha is host address duple (host, port) listen interfaces. host = “” or “0.0.0.0” means listen on all interfaces. bs is buffer size. bl is backlog size of not yet accepted concurrent tcp connections.
- accept()
Accept new connection nonblocking Returns duple (cs, ca) of connected socket and connected host address Otherwise if no new connection returns (None, None)
- actualBufSizes()
Returns duple of the the actual socket send and receive buffer size (send, receive)
- close()
Closes listen socket.
- open()
Opens binds listen socket in non blocking mode.
- if socket not closed properly, binding socket gets error
OSError: (48, ‘Address already in use’)
- reopen(**kwa)
Idempotently opens listen socket
- serviceAccepts()
Service any accept requests Adds to .cxes dict key by ca
- class hio.core.tcp.serving.EchoServerDoer(server, **kwa)
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
- exit()
- recur(tyme)
- class hio.core.tcp.serving.Remoter(ha, ca, cs, tymeout=None, refreshable=True, bs=8096, wl=None, **kwa)
Bases:
TymeeClass to service an incoming nonblocking TCP connection from a remote client. Should only be used by an Acceptor subclass such as Server
- Tymeout = 0.0
- __init__(ha, ca, cs, tymeout=None, refreshable=True, bs=8096, wl=None, **kwa)
- Initialization method for instance.
ha is host address duple (host, port) near side of connection. ca is connection address used as key in server ixes. cs is connection socket object. tymeout is tymeout for .tymer. refreshable True means tx/rx activity refreshes timer. bs is buffer size. wl is WireLog object if any.
- clearRxbs()
Clear .rxbs
- close()
Shutdown and close connected socket .cs
- receive()
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
- refresh()
Restart tymer
- send(data)
Perform non blocking send on connected socket .cs. Return number of bytes sent
data is string in python2 and bytes in python3
- serviceReceiveOnce()
Retrieve from server only one reception
- serviceReceives()
Service receives until no more
- serviceSends()
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
- shutdown(how=2)
Shutdown connected socket .cs
- shutdownReceive()
Shutdown receive on connected socket .cs
- shutdownSend()
Shutdown send on connected socket .cs
- tx(data)
Queue data onto .txbs
- wind(tymth)
Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth
- class hio.core.tcp.serving.RemoterTls(context=None, version=None, certify=None, keypath=None, certpath=None, cafilepath=None, **kwa)
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
- connected
True means TLS handshake completed False otherwise
- Type:
bool
- aborted
True means client aborted TLS handshake False otherwise
- Type:
bool
- __init__(context=None, version=None, certify=None, keypath=None, certpath=None, cafilepath=None, **kwa)
- Initialization method for instance.
context is tls/ssl context object; if None use default. version is ssl version; if None use default. certify is cert requirement; if None use default (ssl.CERT_NONE, ssl.CERT_OPTIONAL, ssl.CERT_REQUIRED). keypath is local server PKI private key file path; if given apply. certpath is local server PKI public cert file path; if given apply. cafilepath is cert authority file path to verify client cert; if given apply.
- close()
Shutdown and close connected socket .cs
- handshake()
Attempt nonblocking ssl handshake to .ha Sets .connected when complete successfully Sets .aborted when client terminates prematurely Keep trying while not connected and not aborted
- receive()
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(data)
Perform non blocking send on connected socket .cs. Return number of bytes sent
data is string in python2 and bytes in python3
- wrap()
Wrap socket .cs in ssl context
- class hio.core.tcp.serving.Server(ha=None, host='', port=56000, tymeout=None, wl=None, **kwa)
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 (tuple[str, int]): (host, port) duple; host = “” or “0.0.0.0” means listen on all interfaces eha (tuple[str, int]): normalized external-facing (host, port) for TLS context bs (int): buffer size ss (socket.socket | None): server listen socket for incoming accept requests axes (deque): accepted connection duples (ca, cs) opened (bool): True if listen socket ss is open; False otherwise
- tymeout
timeout in seconds for connection refresh
- Type:
float
- wl
WireLog instance if any
- Type:
WireLog | None
- ixes
incoming connections indexed by remote (host, port) duple
- Type:
dict
- Tymeout = 1.0
- __init__(ha=None, host='', port=56000, tymeout=None, wl=None, **kwa)
Initialization method for instance. :param ha is TCP/IP: :type ha is TCP/IP: host, port :param host is default TCP/IP host address for listen socket: “” or “0.0.0.0” is listen on all interfaces :param port is default TCP/IP port: :param tymeout is default tymeout for to pass to remoters for incoming connections: :param wl is WireLog instance if any:
- close()
Close all sockets
- closeAllIx()
Shutdown and close all remoter connections
- closeIx(ca)
Shutdown and close remoter given by connection address ca
- removeIx(ca, close=True)
Remove remoter given by connection address ca
- service()
Service connects and service receives and sends for all ix.
- serviceAxes()
Service axes
For each newly accepted connection in .axes create Remoter and add to .ixes keyed by ca
- serviceConnects()
Service connects is method name to be used
- serviceReceivesAllIx()
Service receives for all remoters in .ixes
- serviceReceivesIx(ca)
Service receives for remoter by connection address ca
- serviceSendsAllIx()
Service transmits for all remoters in .ixes
- shutdownIx(ca, how=2)
Shutdown remoter given by connection address ca
- shutdownReceiveIx(ca)
Shutdown send on remoter given by connection address ca
- shutdownSendIx(ca)
Shutdown send on remoter given by connection address ca
- transmitIx(data, ca)
Queue data onto .txbs for remoter given by connection address ca
- wind(tymth)
Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth
- class hio.core.tcp.serving.ServerDoer(server, **kwa)
Bases:
DoerBasic TCP Server Doer
See Doer for inherited attributes, properties, and methods.
- .server is TCP Server instance
Properties:
- __init__(server, **kwa)
Initialize
- Parameters:
instance (server is TCP Server)
- enter(*, temp=None)
Do ‘enter’ context actions. Override in subclass. Not a generator method. Set up resources. Comparable to context manager enter.
- Parameters:
temp (bool | None) – True means use temporary file resources if any None means ignore parameter value. Use self.temp
Inject temp or self.temp into file resources here if any
Doist or DoDoer winds its doers on enter
- exit()
- recur(tyme)
- wind(tymth)
Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth
- class hio.core.tcp.serving.ServerTls(context=None, version=None, certify=None, keypath=None, certpath=None, cafilepath=None, **kwa)
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 (tuple[str, int]): (host, port) duple; host = “” or “0.0.0.0” means listen on all interfaces eha (tuple[str, int]): normalized external-facing (host, port) for TLS context bs (int): buffer size ss (socket.socket | None): server listen socket for incoming accept requests axes (deque): accepted connection duples (ca, cs) opened (bool): True if listen socket ss is open; False otherwise timeout (float): timeout in seconds for connection refresh wl (WireLog | None): WireLog instance if any ixes (dict): incoming connections indexed by remote (host, port) duple
- context
TLS context instance
- Type:
ssl.SSLContext | None
- version
TLS version
- Type:
int | None
- certify
True to require client cert verification
- Type:
bool | None
- keypath
path to key file
- Type:
str | None
- certpath
path to cert file
- Type:
str | None
- cafilepath
path to CA file
- Type:
str | None
- __init__(context=None, version=None, certify=None, keypath=None, certpath=None, cafilepath=None, **kwa)
Initialization method for instance.
- serviceAxes()
Service accepteds
For each new accepted connection create RemoterTLS and add to .cxes Not Handshaked
- serviceConnects()
Service accept and handshake attempts For each successful handshake add to .ixes.
- serviceCxes()
Service handshakes for every remoter in .cxes If successful move to .ixes
- hio.core.tcp.serving.initServerContext(context=None, version=None, certify=None, keypath=None, certpath=None, cafilepath=None)
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 is the tls/ssl context object; if None use default. version is ssl protocol version; if None use default. certify is cert requirement; if None use default (ssl.CERT_NONE, ssl.CERT_OPTIONAL, ssl.CERT_REQUIRED). keypath is local server PKI private key file path; if given apply to context. certpath is local server PKI public cert file path; if given apply to context. cafilepath is cert authority file path to verify client cert; if given apply.
- hio.core.tcp.serving.openServer(cls=None, **kwa)
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.
hio.core.tcp.tcping module
hio.core.tcping Module
- class hio.core.tcp.tcping.Peer(**kwa)
Bases:
ServerNonblocking TCP Socket Peer Class. Supports both incoming and outgoing connections.
- __init__(**kwa)
Initialization method for instance.
Module contents
hio.core.tcp Package