Receiving of multiple requests with Simple HTTP Server

The Clever Internet Suite library provides a special TclSimpleHttpServer component that works in single-threaded blocking mode.

The code below runs the listening in a loop. The requests are accepted until you call to the stop resource name in your web browser.

  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