hio.core.udp package

Submodules

hio.core.udp.udping module

hio.core.udp.udping Module

class hio.core.udp.udping.Peer(*, name='main', ha=None, host='127.0.0.1', port=55000, bc=None, bs=None, wl=None, bcast=False, reopen=False, **kwa)

Bases: Mixin

Class to manage non blocking I/O on UDP socket.

Class Attributes:

BufSize (int): used to set default buffer size for transport datagram buffers MaxGramSize (int): max bytes in in datagram for this transport

name

unique identifier of peer for management purposes

Type:

str

ha

host address of form (host,port) of type (str, int) of this peer’s socket address.

Type:

tuple

bc

count of transport buffers of MaxGramSize

Type:

int | None

bs

buffer size

Type:

int

wl

instance ref for debug logging of over the wire tx and rx

Type:

WireLog

ls

local socket of this Peer

Type:

socket.socket

opened

True local socket is created and opened. False otherwise

Type:

bool

bcast

True enables sending to broadcast addresses from local socket False otherwise

Type:

bool

Properties:

host (str): element of .ha duple port (int): element of .ha duple path (tuple): .ha (host, port) alias to match .uxd

BufSize = 65535
MaxGramSize = 1240
__init__(*, name='main', ha=None, host='127.0.0.1', port=55000, bc=None, bs=None, wl=None, bcast=False, reopen=False, **kwa)

Initialization method for instance. name is a unique identifier of peer for management purposes. ha is a local socket (host, port) address duple of type (str, int). host is address where ‘’ means any interface on host. port is socket port. bc is count of transport buffers of MaxGramSize. bs is buffer size of transport buffers; when bc is provided, bs = bc * MaxGramSize. When bc is not provided, bs uses provided value or defaults to BufSize. wl is a WireLog instance ref for debug logging of over the wire tx/rx. bcast enables sending to broadcast addresses from local socket. reopen True means (re)open with this init; False means open later.

actualBufSizes()

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

close()

Closes socket.

property host

Property that returns host in .ha duple

open()

Opens socket in non blocking mode.

if socket not closed properly, binding socket gets error

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

property path

Property that returns .ha duple stub to match uxd interface

property port

Property that returns port in .ha duple

receive(**kwa)

Perform non blocking read on socket.

Returns:

tuple of form (data, sa) if no data then returns (b’’,None) but always returns a tuple with two elements

reopen(**kwa)

Idempotently open socket

send(data, dst, **kwa)

Perform non blocking send on socket.

Returns:

count of bytes actually sent, may be less than len(data).

Return type:

cnt (int)

Parameters:
  • data (bytes | bytearray) – payload to send (txbs)

  • dst (str) – udp destination addr duple of form (host: str, port: int)

class hio.core.udp.udping.PeerDoer(peer, **kwa)

Bases: Doer

Basic UDP Peer Doer Stub Override in Subclass To test in WingIde must configure Debug I/O to use external console See Doer for inherited attributes, properties, and methods.

See Doer for inherited attributes, properties, and methods.

.peer is UDP Peer instance
__init__(peer, **kwa)

Initialize instance.

Parameters:

instance (peer is UXD Peer)

enter(*, temp=None)

Do ‘enter’ context actions. Override in subclass. Not a generator method. Set up resources. Comparable to context manager enter.

temp is bool or None. True means use temporary file resources if any. None means ignore parameter value and use self.temp.

Inject temp or self.temp into file resources here if any.

exit()

Close peer resources.

recur(tyme)

Override to service receives and sends.

hio.core.udp.udping.openPeer(cls=None, name='test', **kwa)

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

Parameters:
  • cls (Class) – instance of subclass instance

  • name (str) – unique identifier of peer. Enables management of Peer sockets by name.

Usage:
with openPeer() as peer0:

peer0.receive()

with openPeer(cls=PeerBig) as peer0:

peer0.receive()

Module contents

hio.core.udp Package