This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to catch the moment when NDK has received data from TCP or UDP socket?

Dear e2e community!

I use NDK socet API for connection to a TCP/IP server. After connect(), I need to receive data from server.

Can I declare a callback function, which will be called after the data from TCP/IP server is received?

If yes, how can i do it?

I understand, I can call recv(SOCKET s, void *pbuf, int size, int flags); or recvfrom(SOCKET s, void *pbuf, int size, int flags, PSA pName, int *plen); with flags = MSG_WAITALL or MSG_DONTWAIT. But it will "hang" my task (with flags = MSG_WAITALL ) or I must periodically call recv with  flags = MSG_DONTWAIT. Could You suggest any alternative method?

My platform:TMS320C6747EVM (OMAPL137EVM);  CCS3.3; NDK2.0.0; DSP/BIOS 5.33.01;

 

Thank You in advance,

Vitalii

  • Hi Vitalii,

    recv and recvfrom are part of the TCP/IP stack standard.  Callbacks cannot be hooked into the stack to handle cases where information is received.

    Vitalii Kukush said:

     or I must periodically call recv with  flags = MSG_DONTWAIT. Could You suggest any alternative method?

    It is a common practice to not block waiting for data.  This approach will require that your application be able to handle situations where the data is not received all at once (maintain a data buffer and count of bytes received, etc).

    Thanks,

    -- Emmanuel