Sample code for 30+ languages & platforms
Unicode C++

Poll a Socket for Available Data

See more Socket/SSL/TLS Examples

Demonstrates Socket.PollDataAvailable, which performs a nonblocking check for readable activity and returns whether data or another read-ready condition is present.

Background. This lets an application check for incoming data without blocking, for example in an event loop that services multiple tasks.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkSocketW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkSocketW socket;

    //  Connect to the server using TLS.
    bool bTls = true;
    int maxWaitMs = 5000;
    success = socket.Connect(L"example.com",5000,bTls,maxWaitMs);
    if (success == false) {
        wprintf(L"%s\n",socket.lastErrorText());
        return;
    }

    //  Perform a nonblocking check for readable data.  Returns true when data or another read-ready
    //  condition is present, and false when nothing is immediately available.
    bool bAvailable = socket.PollDataAvailable();
    if (bAvailable != true) {
        wprintf(L"No data is immediately available.\n");
    }
    else {
        wprintf(L"Data is available to read.\n");
    }
    }