digidotcom / xbee_ansic_library

A collection of portable ANSI C code for communicating with Digi International's XBee wireless radio modules in API mode.
204 stars 116 forks source link

need callback when remote end closes the TCP connection #19

Closed craffert0 closed 5 years ago

craffert0 commented 5 years ago

In the documentation for API mode behavior for outgoing TCP and SSL connections, it says "a connection is closed when the remote end closes the connection...". How can I get a notification (or poll) when this happens?

I am using API operating mode, and our frame handlers look like this:

const xbee_dispatch_table_entry_t xbee_frame_handlers[] = {
    XBEE_FRAME_HANDLE_LOCAL_AT,
    {XBEE_FRAME_RECEIVE_IPV4, 0, ipv4_rx_handler, nullptr},
    {XBEE_FRAME_TX_STATUS, 0, tx_status_handler, nullptr},
    {XBEE_FRAME_MODEM_STATUS, 0, modem_status_handler, nullptr},
    {XBEE_FRAME_RECEIVE_SMS, 0, sms_rx_handler, nullptr},
    XBEE_FRAME_TABLE_END};

When we receive data from the remote host, we get a callback on ipv4_rx_handleras expected. But when the remote host explicitly closes its end of the TCP/IP connection, we never get a callback on anything.

Is there another frame handler that we can set up? Or a setting to get a zero-length data result on the receive handle? Or something to poll?

tomlogic commented 5 years ago

I'm sad to report that the existing XBee Cellular API frames don't include a method for the module to notify the host that the remote end has closed the connection. If this is an important feature for you, I suggest pushing on your sales contact at Digi International to have them update the product's APIs to provide a better sockets interface.

tomlogic commented 4 years ago

I recently pushed code to use the new Sockets API frames, which include notification of closed sockets. Take a look at xbee/sockets.h and xbee/xbee_sockets.c for support code, and the socket_test and xbee_netcat sample programs.