hio.core.udp.udping

hio.core.udp.udping Module

Module Contents

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: hio.hioing.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

property path

Property that returns .ha duple stub to match uxd interface

property host

Property that returns host in .ha duple

property port

Property that returns port in .ha duple

actualBufSizes()

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

open()

Opens socket in non blocking mode.

if socket not closed properly, binding socket gets error

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

reopen(**kwa)

Idempotently open socket

close()

Closes socket.

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

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)

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()

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

Bases: hio.base.doing.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
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.

recur(tyme)

Override to service receives and sends.

exit()

Close peer resources.