Sample code for 30+ languages & platforms
Delphi DLL

Accept the Next Incoming Connection

See more Socket/SSL/TLS Examples

Demonstrates Socket.AcceptNext, which waits for and accepts the next incoming connection on a listening socket, delivering it as a new connected Socket.

Background. A maxWaitMs of 0 waits indefinitely; a positive value waits up to that many milliseconds. For a TLS listener, acceptance includes the server-side TLS handshake.

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
socket: HCkSocket;
connectedSock: HCkSocket;

begin
success := False;

socket := CkSocket_Create();

success := CkSocket_BindAndListen(socket,5000,25);
if (success = False) then
  begin
    Memo1.Lines.Add(CkSocket__lastErrorText(socket));
    Exit;
  end;

//  Wait for and accept the next incoming connection on the listening socket.  maxWaitMs = 0 waits
//  indefinitely; a positive value waits up to that many milliseconds.  For a TLS listener, acceptance
//  includes the server-side TLS handshake.
connectedSock := CkSocket_Create();
success := CkSocket_AcceptNext(socket,20000,connectedSock);
if (success = False) then
  begin
    Memo1.Lines.Add(CkSocket__lastErrorText(socket));
    Exit;
  end;
Memo1.Lines.Add('Accepted a connection from ' + CkSocket__remoteIpAddress(connectedSock));

CkSocket_Dispose(socket);
CkSocket_Dispose(connectedSock);