是这样的各位,我的程序要对全部的客户端进行一次性的相当于轮寻的操作,就是对多个客户端循环操作。我的思路是:我用indy的idtcpserver对客户端发命令,当一台出错(比如断开)的时候,就报错,然后结束当前线程,但进入下次循环(indy的List会报错),居然就无法进行了,实现这样一个功能这样的代码应该如何组织呢??(我的客户端不是电脑,是设备,比如抄表机之类的);
-------------------------------------
下面是我出错时候的处理
try
List := Idserver.Threads.LockList;
TIdPeerThread(List.Items[Index]).Connection.ReadTimeOut := 3000;
TIdPeerThread(List.Items[Index]).Connection.WriteBuffer(buffcommand,bufflength);
{将所接收到的16进制命令存放到byte数组}
TIdPeerThread(List.Items[Index]).Connection.ReadBuffer(buffResult,ResultLength);
IdServer.Threads.UnlockList;
except
on E:Exception do
begin
showmessage('传输中出现错误:'+E.Message+'抄写失败!!'); Client:=Pointer(TIdPeerThread(List.Items[Index]).Data);
CollIPs.Delete(CollIPs.IndexOf(Client.LocalIP));//IP列表里面删除当前出错的IP
TIdPeerThread(List.Items[Index]).Stop;//停止当前线程
IdServer.Threads.UnlockList;
。
--------------------------------------
以下是我的循环:
CollCount:=CollIps.Count;
i:=0;
while i<CollCount do
begin
................................................
StrResult:=OperateForColl(ReadIDCOmmand,i,22);//这个函数包含上面的出错处理。
if StrResult ='' then
begin
i:=0;
CollCount := CollIps.Count;
continue; //回收数据为空则退出进入下次循环。
end;
..............................................
inc(i);
end;
--------------------------------------------------------------
项目很急,谢谢大家。
-------------------------------------
下面是我出错时候的处理
try
List := Idserver.Threads.LockList;
TIdPeerThread(List.Items[Index]).Connection.ReadTimeOut := 3000;
TIdPeerThread(List.Items[Index]).Connection.WriteBuffer(buffcommand,bufflength);
{将所接收到的16进制命令存放到byte数组}
TIdPeerThread(List.Items[Index]).Connection.ReadBuffer(buffResult,ResultLength);
IdServer.Threads.UnlockList;
except
on E:Exception do
begin
showmessage('传输中出现错误:'+E.Message+'抄写失败!!'); Client:=Pointer(TIdPeerThread(List.Items[Index]).Data);
CollIPs.Delete(CollIPs.IndexOf(Client.LocalIP));//IP列表里面删除当前出错的IP
TIdPeerThread(List.Items[Index]).Stop;//停止当前线程
IdServer.Threads.UnlockList;
。
--------------------------------------
以下是我的循环:
CollCount:=CollIps.Count;
i:=0;
while i<CollCount do
begin
................................................
StrResult:=OperateForColl(ReadIDCOmmand,i,22);//这个函数包含上面的出错处理。
if StrResult ='' then
begin
i:=0;
CollCount := CollIps.Count;
continue; //回收数据为空则退出进入下次循环。
end;
..............................................
inc(i);
end;
--------------------------------------------------------------
项目很急,谢谢大家。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货