on_sock_data_arrival Event

Function:

For sockets not using TLS, this event is generated when at least one data byte is present in the RX buffer of the socket (i.e., for this socket, sock.rxlen > 0). When the socket is using TLS, this event is generated when at least one data byte is present in the TLS RX buffer of the socket (i.e., for this socket, sock.tlsrxlen > 0).

Declaration:

on_sock_data_arrival

See Also:

sock.nextudpdatagram

Details

When the event handler for this event is entered, the sock.num property is automatically switched to the socket for which this event was generated. Another on_sock_data_arrival event on a particular socket is never generated until the previous one is processed.

For sockets not using TLS:

Use the sock.getdata method to extract the data from the RX buffer.

For TCP (sock.protocol = 1 — PL_SOCK_PROTOCOL_TCP), there is no separation into individual packets and you get all arriving data as a "stream." You don't have to process all data in the RX buffer at once. If you exit the on_sock_data_arrival event handler while there is still some unprocessed data in the RX buffer, another on_sock_data_arrival event will be generated immediately.

For UDP ( sock.protocol = 0 — PL_SOCK_PROTOCOL_UDP), the RX buffer preserves datagram boundaries. Each time you enter the on_sock_data_arrival event handler, you get to process the next UDP datagram. If you do not process the entire datagram contents, the datagram's unread portion is discarded once you exit the event handler.

This event is not generated for a particular socket when buffer redirection is set for this socket through the sock.redir method.

For a socket using Transport Layer Security (TLS):

Use the sock.tlsgetdata method to extract the data from the TLS RX buffer.

Exiting the on_sock_data_arrival event handler while there is still unprocessed data in the TLS RX buffer will result in another on_sock_data_arrival event being generated immediately. The contents of the RX buffer are not taken into account and the event is not triggered even if the RX buffer is not empty.