Sample code for 30+ languages & platforms
Delphi DLL

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 Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
socket: HCkSocket;
bTls: Boolean;
maxWaitMs: Integer;
bAvailable: Boolean;

begin
success := False;

socket := CkSocket_Create();

//  Connect to the server using TLS.
bTls := True;
maxWaitMs := 5000;
success := CkSocket_Connect(socket,'example.com',5000,bTls,maxWaitMs);
if (success = False) then
  begin
    Memo1.Lines.Add(CkSocket__lastErrorText(socket));
    Exit;
  end;

//  Perform a nonblocking check for readable data.  Returns 1 when data or another read-ready
//  condition is present, and 0 when nothing is immediately available.
bAvailable := CkSocket_PollDataAvailable(socket);
if (bAvailable <> True) then
  begin
    Memo1.Lines.Add('No data is immediately available.');
  end
else
  begin
    Memo1.Lines.Add('Data is available to read.');
  end;

CkSocket_Dispose(socket);