Newsgroups : Borland : borland.public.delphi.internet.winsock : 2005 Jul : Indy 9. TidSimpleServer. How to detect when client was connected.
| Subject: | Indy 9. TidSimpleServer. How to detect when client was connected. |
| Posted by: | "Ender" (linuxmustd..@hotmail.com) |
| Date: | Thu, 21 Jul 2005 17:21:22 |
Hi, all.
I'm writing a very simple single threaded server. It should listen
connection on certain port, receive client connection, read string sent by a
client, do something useful, then return answer to client, disconnect and
exit. The problem i encountered is that i cannot detect when connection to
the server is made. I'm downloaded Indy demos and it does not contain a
single example with TidSimpleServer. Documentation is very brief and does
not contain code examples.
My code roughly can be represented as following:
Assume that Server declared as Server:TidSimpleServer and contained by data
module. BoundPort and ReadTimeout properties are set.
const
IdleTimeOut=60;
var
ListeningFrom:TDateTime;
InputLine,OutputLine:String;
begin
Server.BeginListen;
ListeningFrom:=Now;
while SecondsBetween(Now, ListeningFrom)<IdleTimeout do
begin
if Server.Connected then
begin
InputLine:=Server.ReadLn(#13,10000,1024);
OutputLine:=DoSomethingUseful(InputLine);
Server.WriteLn(OutputLine);
Exit;
end;
Sleep(500);
end;
...
Server.Connected always return TRUE and Server.ReadLn immediately fails with
error 'Socket not connected'. I'm tried to detect connection in the OnStatus
event, however it does not get fired even when client reports that it
successfully connected to the server. Do this component work at all?