indy10 tcpclient 已经断开连接,为什么connected还为true
1个回答
2017-05-10
展开全部
TIdTCPClientCustom.Connect源码如下,中文注释是自己写的。
procedure TIdTCPClientCustom.Connect;begin if Connected then begin EIdAlreadyConnected.Toss(RSAlreadyConnected); //如果已经连接则抛出AlreadyConnected的异常 end; if Host = '' then begin EIdHostRequired.Toss(''); //如果Host为空,则抛出EIdHostRequired的异常 end; if Port = 0 then begin EIdPortRequired.Toss(''); //如果Host为空,则抛出EIdPortRequired的异常 end; if IOHandler = nil then begin IOHandler := MakeImplicitClientHandler; IOHandler.OnStatus := OnStatus; //改变OnStatus的状态 ManagedIOHandler := True; end; try // Bypass GetDestination if FDestination <> '' then begin IOHandler.Destination := FDestination; end;{BGO: not any more, TIdTCPClientCustom has precedence now (for port protocols, and things like that) // We retain the settings that are in here (filled in by the user) // we only do this when the iohandler has no settings, // because the iohandler has precedence if (IOHandler.Port = 0) and (IOHandler.Host = '') then begin IOHandler.Port := FPort; IOHandler.Host := FHost; end;} IOHandler.Port := FPort; //BGO: just to make sure IOHandler.Host := FHost; IOHandler.ConnectTimeout := FConnectTimeout; IOHandler.ReadTimeout := FReadTimeout; if Socket <> nil then begin Socket.BoundIP := FBoundIP; Socket.BoundPort := FBoundPort; Socket.BoundPortMin := FBoundPortMin; Socket.BoundPortMax := FBoundPortMax; Socket.IPVersion := FIPVersion; Socket.ReuseSocket := FReuseSocket; Socket.UseNagle := FUseNagle; Socket.OnBeforeBind := FOnBeforeBind; Socket.OnAfterBind := FOnAfterBind; Socket.OnSocketAllocated := FOnSocketAllocated; end; IOHandler.Open; //打开IO if IOHandler.Intercept <> nil then begin IOHandler.Intercept.Connect(Self); end; DoStatus(hsConnected, [Host]); DoOnConnected; //调用OnConnected函数 except //捕捉异常 if IOHandler <> nil then begin IOHandler.Close; if ManagedIOHandler then begin IOHandler := nil; // RLebeau - SetIOHandler() will free the IOHandler end; end; raise; end;end;
procedure TIdTCPClientCustom.Connect;begin if Connected then begin EIdAlreadyConnected.Toss(RSAlreadyConnected); //如果已经连接则抛出AlreadyConnected的异常 end; if Host = '' then begin EIdHostRequired.Toss(''); //如果Host为空,则抛出EIdHostRequired的异常 end; if Port = 0 then begin EIdPortRequired.Toss(''); //如果Host为空,则抛出EIdPortRequired的异常 end; if IOHandler = nil then begin IOHandler := MakeImplicitClientHandler; IOHandler.OnStatus := OnStatus; //改变OnStatus的状态 ManagedIOHandler := True; end; try // Bypass GetDestination if FDestination <> '' then begin IOHandler.Destination := FDestination; end;{BGO: not any more, TIdTCPClientCustom has precedence now (for port protocols, and things like that) // We retain the settings that are in here (filled in by the user) // we only do this when the iohandler has no settings, // because the iohandler has precedence if (IOHandler.Port = 0) and (IOHandler.Host = '') then begin IOHandler.Port := FPort; IOHandler.Host := FHost; end;} IOHandler.Port := FPort; //BGO: just to make sure IOHandler.Host := FHost; IOHandler.ConnectTimeout := FConnectTimeout; IOHandler.ReadTimeout := FReadTimeout; if Socket <> nil then begin Socket.BoundIP := FBoundIP; Socket.BoundPort := FBoundPort; Socket.BoundPortMin := FBoundPortMin; Socket.BoundPortMax := FBoundPortMax; Socket.IPVersion := FIPVersion; Socket.ReuseSocket := FReuseSocket; Socket.UseNagle := FUseNagle; Socket.OnBeforeBind := FOnBeforeBind; Socket.OnAfterBind := FOnAfterBind; Socket.OnSocketAllocated := FOnSocketAllocated; end; IOHandler.Open; //打开IO if IOHandler.Intercept <> nil then begin IOHandler.Intercept.Connect(Self); end; DoStatus(hsConnected, [Host]); DoOnConnected; //调用OnConnected函数 except //捕捉异常 if IOHandler <> nil then begin IOHandler.Close; if ManagedIOHandler then begin IOHandler := nil; // RLebeau - SetIOHandler() will free the IOHandler end; end; raise; end;end;
微测检测5.10
2023-07-11 广告
2023-07-11 广告
IEC62133与en62133的区别如下:1. 认证机构不同:IEC62133是国际的标准,它以国际通用的标准进行生产;而en62133采用的是欧盟的标准,它使用欧盟的生产需求进行生产。2. 宗旨不同:IEC62133的宗旨是促进电气、电...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询