服务端:IdTCPServer
客户端:IdTCPClient服务端程序要定时查看先前连接的用户是否因为断电或其它异常而导致与服务端失去连接.
所以我在主线程中用了一个定时器<5秒刷新一次>:
//定时刷新.
procedure TfrmMain.tmClientStatusTimer(Sender: TObject);
var
AThread: TIdPeerThread;
Machine:PMachine;
i: integer;
begin
with trdlsClients.LockList do
begin
for i := 0 to Count -1 do
begin
Machine:= Items[i];
AThread := Machine.Thread;
if AThread.Connection.Connected then
AThread.Connection.WriteLn('ONLINE客户端');
end;
trdlsClients.UnlockList;
end;
//注 :trdlsClients为全局TThreadList变量;存储已经连接的客户.
=================================================
//服务器端检查接收的命令并做相应处理
procedure TfrmMain.IdTCPServerExecute(AThread: TIdPeerThread);
begin
//如果客户是连接状态,则回送命令.
if AThread.Connection.ReadLn(EOL) = 'ONLINE客户端' then
begin
end
end;
====================================================================
我现在要做的事,把未在线的客户端在ListView中更新为"未连接"状态....不懂得如何写?
客户端:IdTCPClient服务端程序要定时查看先前连接的用户是否因为断电或其它异常而导致与服务端失去连接.
所以我在主线程中用了一个定时器<5秒刷新一次>:
//定时刷新.
procedure TfrmMain.tmClientStatusTimer(Sender: TObject);
var
AThread: TIdPeerThread;
Machine:PMachine;
i: integer;
begin
with trdlsClients.LockList do
begin
for i := 0 to Count -1 do
begin
Machine:= Items[i];
AThread := Machine.Thread;
if AThread.Connection.Connected then
AThread.Connection.WriteLn('ONLINE客户端');
end;
trdlsClients.UnlockList;
end;
//注 :trdlsClients为全局TThreadList变量;存储已经连接的客户.
=================================================
//服务器端检查接收的命令并做相应处理
procedure TfrmMain.IdTCPServerExecute(AThread: TIdPeerThread);
begin
//如果客户是连接状态,则回送命令.
if AThread.Connection.ReadLn(EOL) = 'ONLINE客户端' then
begin
end
end;
====================================================================
我现在要做的事,把未在线的客户端在ListView中更新为"未连接"状态....不懂得如何写?
,在一定时间内没有回复就是断线的,
行不???