hio.core.tcp
hio.core.tcp Package
Submodules
Package Contents
Classes
Nonblocking TCP Socket Client Class. |
|
Outgoer with Nonblocking TLS/SSL support |
|
Basic TCP Client |
|
Nonblocking TCP Socket Server Class. |
|
Server with Nonblocking TLS/SSL support |
|
Class to service an incoming nonblocking TCP connection from a remote client. |
|
Basic TCP Server Doer |
|
Echo TCP Server |
Functions
|
Wrapper to create and open TCP Client instances |
|
Wrapper to create and open TCP Server instances |
- hio.core.tcp.openClient(cls=None, **kwa)[source]
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()
- class hio.core.tcp.Client(tymeout=None, ha=None, host='127.0.0.1', port=56000, reconnectable=None, bs=8096, txbs=None, rxbs=None, wl=None, **kwa)[source]
Bases:
hio.base.tyming.TymeeNonblocking TCP Socket Client Class.
See tyming.Tymee for inherited attributes, properties, and methods
Attributes:
Properties:
Methods:
- Tymeout = 0.0
- Reconnectable = False
- property host(self)
Property that returns host in .ha duple
- property port(self)
Property that returns port in .ha duple
- property accepted(self)
Property that returns accepted state of TCP socket
- property connected(self)
Property that returns connected state of TCP socket Non-tls tcp is connected when accepted
- wind(self, tymth)
Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth
- reinitHostPort(self, ha=None, hostname='127.0.0.1', port=56000)
Reinit self.ha and self.hostname from ha = (host, port) or hostname port self.ha is of form (host, port) where host is either dns name or ip address self.hostname is hostname as dns name host eventually is host ip address output from normalizeHost()
- actualBufSizes(self)
Returns duple of the the actual socket send and receive buffer size (send, receive)
- open(self)
Opens connection socket in non blocking mode.
- if socket not closed properly, binding socket gets error
OSError: (48, ‘Address already in use’)
- reopen(self)
Idempotently opens socket
- shutdown(self, how=socket.SHUT_RDWR)
Shutdown connected socket .cs
- shutdownSend(self)
Shutdown send on connected socket .cs
- shutdownReceive(self)
Shutdown receive on connected socket .cs
- close(self)
Shutdown and close connected socket .cs
- refresh(self)
Restart timer
- accept(self)
Attempt nonblocking acceptance connect to .ha Returns True if successful Returns False if not so try again later
- connect(self)
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
- serviceConnect(self)
Service connection attempt If not already connected make a nonblocking attempt Returns .connected
- receive(self)
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
- serviceReceives(self)
Service receives until no more
- serviceReceiveOnce(self)
Retrieve from server only one reception
- clearRxbs(self)
Clear .rxbs
- send(self, data)
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)
Copy data onto .txbs, .extend copies data.
- serviceSends(self)
Service sends (transmits) of data in .txbs bytearray Attempt to send all of .txbs. Delete what is actually sent.
- service(self)
Service connect, txbs, and receives.
- class hio.core.tcp.ClientTls(context=None, version=None, certify=None, hostify=None, certedhost='', keypath=None, certpath=None, cafilepath=None, **kwa)[source]
Bases:
ClientOutgoer with Nonblocking TLS/SSL support Nonblocking TCP Socket Client Class.
Attributes:
Properties:
Methods:
- property connected(self)
Property that returns connected state of TCP socket TLS tcp is connected when accepted and handshake completed
- close(self)
Shutdown and close connected socket .cs
- wrap(self)
Wrap socket .cs in ssl context
- handshake(self)
Attempt nonblocking ssl handshake to .ha Returns True if successful Returns False if not so try again later
- connect(self)
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
- receive(self)
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(self, data)
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.ClientDoer(client, **kwa)[source]
Bases:
hio.base.doing.DoerBasic TCP Client
See Doer for inherited attributes, properties, and methods.
- .client is TCP Client instance
- wind(self, tymth)
Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth
- enter(self)
- recur(self, tyme)
- exit(self)
- hio.core.tcp.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.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
- Tymeout = 1.0
- wind(self, tymth)
Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth
- serviceAxes(self)
Service axes
For each newly accepted connection in .axes create Remoter and add to .ixes keyed by ca
- serviceConnects(self)
Service connects is method name to be used
- shutdownIx(self, ca, how=socket.SHUT_RDWR)
Shutdown remoter given by connection address ca
- shutdownSendIx(self, ca)
Shutdown send on remoter given by connection address ca
- shutdownReceiveIx(self, ca)
Shutdown send on remoter given by connection address ca
- closeIx(self, ca)
Shutdown and close remoter given by connection address ca
- closeAllIx(self)
Shutdown and close all remoter connections
- close(self)
Close all sockets
- removeIx(self, ca, close=True)
Remove remoter given by connection address ca
- serviceReceivesIx(self, ca)
Service receives for remoter by connection address ca
- serviceReceivesAllIx(self)
Service receives for all remoters in .ixes
- transmitIx(self, data, ca)
Queue data onto .txbs for remoter given by connection address ca
- serviceSendsAllIx(self)
Service transmits for all remoters in .ixes
- service(self)
Service connects and service receives and sends for all ix.
- class hio.core.tcp.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)
Service accepteds
For each new accepted connection create RemoterTLS and add to .cxes Not Handshaked
- serviceCxes(self)
Service handshakes for every remoter in .cxes If successful move to .ixes
- serviceConnects(self)
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.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
- Tymeout = 0.0
- wind(self, tymth)
Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth
- shutdown(self, how=socket.SHUT_RDWR)
Shutdown connected socket .cs
- shutdownSend(self)
Shutdown send on connected socket .cs
- shutdownReceive(self)
Shutdown receive on connected socket .cs
- close(self)
Shutdown and close connected socket .cs
- refresh(self)
Restart tymer
- receive(self)
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)
Service receives until no more
- serviceReceiveOnce(self)
Retrieve from server only one reception
- clearRxbs(self)
Clear .rxbs
- send(self, data)
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)
Queue data onto .txbs
- serviceSends(self)
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.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:
- wind(self, tymth)
Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth
- enter(self)
- recur(self, tyme)
- exit(self)
- class hio.core.tcp.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
- enter(self)
- recur(self, tyme)
- exit(self)