Home

Awesome

XAsyncSockets is an efficient Python/MicroPython library of managed asynchronous sockets.

HC²

Very easy to integrate and very light with one file only :

XAsyncSockets features :

<p align="center"> <img src="diagram.png"> </p>

XAsyncSockets classes :

Class nameDescription
XAsyncSocketsPoolManaged pool of 'XAsyncSocket' objects
XClosedReasonEnumerator of 'XAsyncSocket' closing reasons
XAsyncSocketAbstract class of managed asynchronous sockets
XAsyncTCPServerTCP server implementation of 'XAsyncSocket'
XAsyncTCPClientTCP client implementation of 'XAsyncSocket'
XAsyncUDPDatagramUDP sender/recever implementation of 'XAsyncSocket'
XBufferSlotManaged buffer
XBufferSlotsManaged buffers collection
XFiFoDedicated FiFo queue

XAsyncSockets exceptions :

Class nameDescription
XAsyncSocketsPoolExceptionException class for 'XAsyncSocketsPool'
XAsyncSocketExceptionException class for 'XAsyncSocket'
XAsyncTCPServerExceptionException class for 'XAsyncTCPServer'
XAsyncTCPClientExceptionException class for 'XAsyncTCPClient'
XAsyncUDPDatagramExceptionException class for 'XAsyncUDPDatagram'
XFiFoExceptionException class for 'XFiFo'

XAsyncSocketsPool class details :

MethodArguments
ConstructorNone
GetAllAsyncSocketsNone
GetAsyncSocketByIDid (int)
AsyncWaitEventsthreadsCount=0 (int)
StopWaitEventsNone
PropertyDetails
WaitEventsProcessingReturn True if "WaitEvents" is in processing

( Do not call directly the methods AddAsyncSocket, RemoveAsyncSocket, NotifyNextReadyForReading and NotifyNextReadyForWriting )

XClosedReason class details :

Static variableValue
Error0x00
ClosedByHost0x01
ClosedByPeer0x02
Timeout0x03

XAsyncSocket class details :

MethodArguments
GetAsyncSocketsPoolNone
GetSocketObjNone
CloseNone
PropertyDetails
SocketIDGet the opened socket unique ID
OnClosedGet or set an event of type f(closedReason)
StateGet or set a custom object

XAsyncTCPServer class details :

MethodArguments
Create (static)asyncSocketsPool, srvAddr (tuple of ip and port), srvBacklog=256 (int), bufSlots=None
PropertyDetails
SrvAddrTuple of ip and port
OnClientAcceptedGet or set an event of type f(xAsyncTCPServer, xAsyncTCPClient)

XAsyncTCPClient class details :

MethodArguments
Create (static)asyncSocketsPool, srvAddr (tuple of ip and port), connectTimeout=5 (int), recvBufLen=4096 (int), sendBufLen=4096(int), connectAsync=True (bool)
AsyncRecvLinelineEncoding='UTF-8', onLineRecv=None (function), onLineRecvArg=None (object), timeoutSec=None (int)
AsyncRecvDatasize=None (int), onDataRecv=None (function), onDataRecvArg=None (object), timeoutSec=None (int)
AsyncSendDatadata (bytes or buffer protocol), onDataSent=None (function), onDataSentArg=None (object)
AsyncSendSendingBuffersize=None (int), onDataSent=None (function), onDataSentArg=None (object)
StartSSLkeyfile=None, certfile=None, server_side=False, cert_reqs=ssl.CERT_NONE, ca_certs=None
StartSSLContextsslContext, serverSide=False
PropertyDetails
SrvAddrTuple of ip and port
CliAddrTuple of ip and port
IsSSLReturn True if SSL is used
SendingBufferGet the existing buffer (memoryview) used to send data
OnFailsToConnectGet or set an event of type f(xAsyncTCPClient)
OnConnectedGet or set an event of type f(xAsyncTCPClient)

XAsyncUDPDatagram class details :

MethodArguments
Create (static)asyncSocketsPool, localAddr=None (tuple of ip and port), recvBufLen=4096 (int), broadcast=False (bool)
AsyncSendDatagramdatagram (bytes or buffer protocol), remoteAddr (tuple of ip and port), onDataSent=None (function), onDataSentArg=None (object)
PropertyDetails
LocalAddrTuple of ip and port
OnRecvGet or set an event of type f(xAsyncUDPDatagram, remoteAddr, datagram)
OnFailsToSendGet or set an event of type f(xAsyncUDPDatagram, datagram, remoteAddr)

XBufferSlot class details :

MethodArguments
Constructorsize (int), keepAlloc=True (bool)
PropertyDetails
AvailableGet or set the availability of the slot
SizeGet the buffer size of the slot
BufferGet the buffer of the slot

XBufferSlots class details :

MethodArguments
ConstructorslotsCount (int), slotsSize (int), keepAlloc=True (bool)
GetAvailableSlotNone
PropertyDetails
SlotsCountGet the number of slots
SlotsSizeGet the buffer size of each slots
SlotsGet the list of slots

XFiFo class details :

MethodArguments
ConstructorNone
Putobj (object)
GetNone
ClearNone
PropertyDetails
EmptyReturn True if the FiFo is empty

By JC`zic for HC² ;')

Keep it simple, stupid :+1: