当前位置:主页>销售管理软件> 列表

当网络断开时,IdTCPClient的Connected仍 找管家婆软件下载

仓库管理软件版1楼: 如题!
此时,调用readln方法时,就不执行后面的语句,如果执行了后面的语句,我还可以通过检查readln的数据来判断,郁闷就在这个地方,readln后就不执行了。

2楼: http://www.itgoogle.com/web/show_art.asp?page=2&id=1533 如商品进销存表格下载

3楼: 我看了,里面有你的要求,还能为你提供许多参考

4楼: SiWeiLiuLang,http://www.itgoogle.com/web/show_art.asp?page=2&id=1533上的文章已经看了
我目前就是这样写的,将writeln和readln都用try...except...end给括起来了,但实际情况是,在正常连接后,拔掉网线,此时在调用writeln和readln根本就不会进入到except中,没有任何反应的就执行了,并且在执行readln后,后面的语句也都不执行了,不明白

5楼: 你的代码帖下吧

6楼: try
if not IdTCPClient1.Connected then
begin
IdTCPClient1.Host:= IPAddr;
IdTCPClient1.Connect;
end;

try
IdTCPClient1.WriteLn(''Hello'');
try
V_ServerMsg:= IdTCPClient1.ReadLn();//当把网线拔下来时,下面的语句就不执行了,同时上面的Connected还是为True

if (V_ServerMsg,19=''Hello World!'') then
Result:= True
else
WriteErrorLog(2);
except
WriteErrorLog(4);
end;
except
WriteErrorLog(3);
end;
except
WriteErrorLog(1);
end

仓库管理软件版7楼: 你的代码并没有判断网络断开啊

8楼: 怎么没有
if not IdTCPClient1.Connected then
不就是吗

9楼: 但问题就是当网线断开了,IdTCPClient1.Connected还是为True

10楼: 你以为程序是神啊...这种物理性断开凭单方面是无法判断的.一般这种程序的处理办法是利用计数器来解决的.例如QQ判断有没有跟服务器断开就是用这方法.

11楼: 设置一套脉搏数据,很多网络游戏就是这样的,定期发送脉搏数据,让对方知道连接状态.超过时间没有收到就timeout了,就重新连接.连接不上就说明被断开了

12楼: 使用以下语句,做一个监视线程:
procedure TLogHandleThread.Execute;
begin
while not Terminated do
begin
try
MainForm.IdTCPClient1.CheckForGracefulDisconnect();
except
MainForm.IdTCPClient1.Disconnect;
end;



if not MainForm.IdTCPClient1.Connected then
try
MainForm.IdTCPClient1.Connect();
except
//
end;

try
if MainForm.IdTCPClient1.Connected then
begin
//写自己的代码
end
except
end;
end;
end;

Determines if the peer has gracefully disconnected.
procedure CheckForGracefulDisconnect(const ARaiseExceptionIfDisconnected: boolean); virtual;

Parameters

const ARaiseExceptionIfDisconnected: boolean = true

Raise an exception when the connection is closed. Default value is True.



Description

CheckForGracefulDisconnect is a procedure used to determine if the connection has closed gracefully.
CheckForGracefulDisconnect calls ReadFromStack using the value in ARaiseExceptionIfDisconnected and a 1 millisecond timeout to verify that the socket handle is ready to perform a read operation.
ReadFromStack updates the ClosedGracefully property and performs exception handling as specified in ARaiseExceptionIfDisconnected. 如管家婆软件下载

13楼: 在连接由于网络的原因意外断开后很难去获得连接是否已断开,此时只用设置ReadTimeout属性值,来判断readln是否超时,就可以认为连接是否断开了,虽然这种方法不太可靠,但如果能将ReadTimeout值设置的合理的话,这种不可靠的情况就基本上可以忽略不记了

仓库管理软件版14楼: indy的IdInWatch控件可以判断。

15楼: Avalon的方法好像可以,虽然不太尽人意,但基本上解决了我的问题,同时也谢谢各位了!!!