Receiving multiple requests using Simple HTTP Server

The Clever Internet Suite library provides a special TclSimpleHttpServer component that works in single-threaded blocking mode.
 
The example starts listening the socket in a loop. Incoming requests are accepted until you request a specific URL in your web browser.
 
If you are looking for a multi-threaded HTTP server component for Delphi, please check out the following Article, the sources are available on GitHub
 
server := TclSimpleHttpServer.Create(nil);
try
  repeat
    server.Listen(80);

    request := server.AcceptRequest();
    uri := server.RequestUri;

    server.ResponseHeader.ContentType := 'text/html';
    server.KeepConnection := False;

    if (Pos('stop', uri) > 0) then
    begin
      server.SendResponse(200, 'OK', '<html><body>Server stopped.</body></html>');
      Break;
    end;

    server.SendResponse(200, 'OK', '<html><body>Your requested the ' + uri + ' resource.</body></html>');
  until False;
finally
  server.Free();
end;
 

Add Feedback