Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Dec : TIdCMDTCPServer
| Subject: | TIdCMDTCPServer |
| Posted by: | "Roberto Colpani" (roberto.colpa..@vetrariafratellicolpani.it) |
| Date: | Wed, 20 Dec 2006 17:14:18 |
I have this problem: on a wirelees network when my notebook go in stanby
mode the TIdCMDTCPServer is never informed and it take the connection of the
notebook active. When I reopen my notebook there is an error that it tell me
that there no connection.
I try to resolve this problem in this way:
on the client side I put a timer that every 1 minute it send a command to
the server;
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.
The proble is that I don't know how to do this. I prouve with
TIDContext.Removefromlist method that it doesn't work. The last version of
my prove is the above code:
procedure TMainForm.Check;
Var
AList, AServerList: TList;
AUser: TConnectedUser;
AllOk: Boolean;
I: Integer;
TimeToCheck, ResultTime: TDateTime;
ASecond: Word;
function GiveSeconds(const Value: String): Word;
Var
AMinutesStr, ASecondsStr: String;
begin
AMinutesStr := Value[1];
AMinutesStr := AMinutesStr + Value[2];
ASecondsStr := Value[4];
ASecondsStr := ASecondsStr + Value[5];
Result := StrToInt(AMinutesStr) * 60;
Result := Result + StrToInt(ASecondsStr);
end;
begin
TimeToCheck := now;
AServerList := ServerTango.Contexts.LockList;
try
if AServerList.Count > 0 then
begin
AList := UserList.LockList;
try
AllOk := False;
while not AllOk do
begin
for I := 0 to AServerList.Count - 1 do
begin
ResultTime := TimeToCheck -
TConnectedUser(AList[I]).BroadCastMessage;
ASecond := GiveSeconds(FormatDateTime('nn:ss', ResultTime));
AllOk := True;
if ASecond > BroadCastInterval then
begin
AllOk := False;
AUser := AList[I];
AList.Delete(I);
AUser.Free;
AServerList.Delete(I);
if AServerList.Count = 0 then
AllOk := True;
Break;
end;
end;
end;
finally
UserList.UnlockList;
end;
end;
finally
ServerTango.Contexts.UnlockList;
end;
end;
it function but when I try to end the server it doesn't.
How can I do this thing?
Perhaps I can intecept when the notebook enter in standby mode and
automatically disconnect from the server. It' s possible to do this and how?