Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Dec : Re: TIdCMDTCPServer
| Subject: | Re: TIdCMDTCPServer |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Wed, 20 Dec 2006 12:40:21 |
"Roberto Colpani" <roberto.colpani@vetrariafratellicolpani.it> wrote in
message news:4589611a@newsgroups.borland.com...
> on a wirelees network when my notebook go in stanby mode the
> TIdCMDTCPServer is never informed
It is not supposed to be. You have to handle power notifications in your
own code. Look at the WM_POWER and WM_POWERBROADCAST window messages.
> it take the connection of the notebook active.
I do not understand what you are trying to say.
> on the client side I put a timer that every 1 minute it send a
> command to the server
If your server application monitors the power notifications properly, then
it can disable the TIdCmdTCPServer before the power is turned off, and
re-activate it when the power resumes. Then the client will receive a
normal disconnect, and when it tries to reconnect it will see that the
server is unavailable, and can keep trying as needed until the server goes
back online later.
> on the server side when the command arrive, it sets the hour of the
> arrive to a field of type TDateTime to my User. I timer every 30
> second check if the delay of the last command sended by every user
> is great of 30 second. If so it must delete the connession.
That is fine. You should keep that in order to detect dead clients in
general, in case of network failures that have nothing to do with power
usage.
> I prouve with TIDContext.Removefromlist method that it doesn't work.
You should not be using that method directly at all. Simply Disconnect()
the client instead, and let the TIdCmdTCPServer handle all of the necessary
clieanup for you.
Try this code instead:
type
TConnectedUser = class(TIdContext)
public
BroadCastMessage: TIdThreadSafeDateTime;
//...
constructor Create(AConnection: TIdTCPConnection; AYarn:
TIdYarn; AList: TIdThreadList = nil); override;
destructor Destroy; override;
end;
constructor TConnectedUser.Create(AConnection: TIdTCPConnection; AYarn:
TIdYarn; AList: TIdThreadList = nil);
begin
inherited Create(AConnection, AYarn, AList);
BroadCastMessage := TIdThreadSafeDateTime.Create;
end;
destructor TConnectedUser.Destroy;
begin
BroadCastMessage.Free;
inherited Destroy;
end;
constructor TMainForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ServerTango.ContextClass := TConnectedUser;
end;
procedure TMainForm.Check;
var
AList: TList;
AUser: TConnectedUser;
I: Integer;
TimeToCheck: TDateTime;
begin
TimeToCheck := IncSecond(Now, -30);
AList := ServerTango.Contexts.LockList;
try
for I := 0 to AList.Count-1 do
begin
AUser := TConnectedUser(AList[I]);
if AUser.BroadCastMessage.Value < TimeToCheck then
begin
try
AUser.Connection.Disconnect;
except
end;
end;
end;
finally
ServerTango.Contexts.UnlockList;
end;
end;
procedure TMainForm.ServerTangoBeforeCommandHandler(ASender:
TIdCmdTCPServer; var AData: string; AContext: TIdContext);
begin
TConnectedUser(AContext).BroadCastMessage.Value := Now;
end;
Gambit