views:

1125

answers:

2

I'm using Delphi 2006 and Indy 10. I create a form and drop down an IdHttpServer component. I make an OnCreate event for the form to set the server active, and I enter these lines for the server's OnCommandGet:

procedure TForm3.IdHTTPServerCommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
   Beep;
   Sleep(10000);
   AResponseInfo.ContentText := DateTimeToStr(Now);
end;

Note the Sleep for 10 seconds.

I then test with Firefox, using 2 browsers. I have the first one connect to "localhost", and I hear a beep right away. I then tab to the 2nd browser, and have it connect to localhost (in less than 10 seconds), but it doesn't beep right away. It waits for the 1st request to complete, then beeps, and waits another 10 seconds.

I thought these components were multi-threaded? Is there some property I can set to make it behave the way I thought it would (both requests would get answered immediately).

A: 

I have used Indy 10 idHTTPServer and it is multithread. What blocking your app might be the "beep" or the "sleep" command. Because although the component is multithread, some commands may still lock the whole process.

BYK
For some reason Indy is waiting for the 1st request to complete before it fires the OnCommandGet for the 2nd request. Its like it has wrapped the OnCommandGet method in a Critical section. It may be using different threads for each request, but that is of no use if Indy still fires them in serial.The Beep and Sleep functions will not block some OTHER thread.
Since I have developed a complete application with the component I'm pretty sure it is multithread. If it won't be a problem post your code and let's examine it together to find the problem ;)
BYK
Thanks, try the code from this link, let me know what you see:http://www.benziegler.com/stuff/IndyTest.zip
I went nuts but could not find the solution. It seems that it accepts and processes the requests in seperate threads but it waits the other thread to stop to actually start doing something. May be it is because we're making the 2 requests from the local machine.
BYK
Thanks for trying. Its very frustrating, it should be multi-threaded but its just not. It shouldn't be a problem to make 2 requests from the same machine.
+3  A: 

Not Indy and the TIdHTTPServer is responsible for this behaviour! It's the webbrowser!

Firefox shares the TCP connection for different requests at the same server.

So, Firefox serializes the 2 requests for the same URI. Open 2 different browsers at the same time (e.g. IE and Firefox), request http://localhost/ in both and you will get the expected result.

And the answer to your question: Yes, of course, every TIdHTTPServer.OnCommandGet event is executed in an own "scheduler" thread, and can be executed simultaneously.

ulrichb
Yes, that's it! I used Firefox and Internet explorer, and got the expected results, thanks very much!There was a bug in my code that showed the same behavior, so when I saw Firefox doing it too I assumed my code was perfect...