ClientTCP: TIdTCPClient;为什么我的ClientTCP想停停不下来

morrisyuan 2008-04-23 11:52:33
请问一下这个问题一般都是什么情况造成的......我该从哪几个方面入手找错误源.....错误提示如附件图片所示:
工程client.exe检测到错误类eidnotconnected,错误类型 not connected 进程中止..


我看了启动时创建的东东,应该都消到了..一运行到ClientTCP.Disconnect;就卡住了..也就是clienttcp连接不能断开

观察进程发现,程序运行好好的时候,进程名叫client,tcp,established(状态),卡住后就状态变成time wait ,名字unknown

代码好长.

procedure TRealMessengerX.ClientLogout();
var
iLoop: Integer;
EmployeePointer: PEmployee;
ChatingForm: TChatingForm;
AudioHandShake: TAudioHandShake;
VideoHandShake: TVideoHandShake;
TransmitFile: TTransmitFile;
MySocket: TMySocket;
begin
if CheckPOP3ThreadHandle <> 0 then TerminateThread(CheckPOP3ThreadHandle, 4);
CheckPOP3ThreadHandle := 0;
LblMailCount.Caption := '0 封电子邮件';
LblMailCount.Enabled := False;

TimerAutoConnect.Enabled := False;
TimerLoging.Enabled := False;
KeepP2PSessionTimer.Enabled := False;

PBLogin.Visible := False;
LblLoging.Visible := False;
LblCancelLogin.Visible := False;
CoolTrayIcon.CycleIcons := False;
MsgAlertQueue.Clear;

TrevUserList.Hide;

STimer.Enabled := False;

MConnect.Enabled := True;
MConnect.Caption := '登录(&I)';
MConnectSet.Enabled := True;
MDisconnect.Enabled := False;
MMyState.Enabled := False;
MSendMsg.Enabled := False;
MSendFile.Enabled := False;
MSendVoice.Enabled := False;
MSendVideo.Enabled := False;
MShowHistory.Enabled := False;
NR1.Enabled := False;
NR2.Enabled := False;
NR3.Enabled := False;
NR4.Enabled := False;
NR5.Enabled := False;
HartTimer.Enabled := False;

for iLoop := ChatingFormList.Count - 1 downto 0 do
begin
ChatingForm := ChatingFormList.Items[iLoop];
ChatingFormList.Remove(ChatingForm);
try
if (ChatingForm is TChatingForm) then ChatingForm.Free;
except
end;
end;

with VideoHandShakes.LockList do
try
for iLoop := Count - 1 downto 0 do
begin
VideoHandShake := Items[iLoop];
VideoHandShake.Free;
VideoHandShakes.Remove(VideoHandShake);
end;
finally
VideoHandShakes.UnlockList;
end;

with AudioHandShakes.LockList do
try
for iLoop := Count - 1 downto 0 do
begin
AudioHandShake := Items[iLoop];
AudioHandShake.Free;
AudioHandShakes.Remove(AudioHandShake);
end;
finally
AudioHandShakes.UnlockList;
end;

with TransmitFiles.LockList do
try
for iLoop := Count - 1 downto 0 do
begin
TransmitFile := Items[iLoop];
TransmitFile.Free;
TransmitFiles.Remove(TransmitFile);
end;
finally
TransmitFiles.UnlockList;
end;

with Employees.LockList do
try
for iLoop := 0 to Count - 1 do
begin
EmployeePointer := Items[iLoop];
EmployeePointer.State := '断开';
EmployeePointer.HaveAudioDevice := False;
EmployeePointer.HaveVideoDevice := False;
UpdateListViewStates(TrevUserList, EmployeePointer.Node); {更新用户状态}
FreeMem(EmployeePointer, SizeOf(Employee));
end;
finally
Employees.UnlockList;
end;
Employees.Clear;
with Branchs.LockList do
try
for iLoop := 0 to Count - 1 do FreeMem(Items[iLoop], SizeOf(Branch));
finally
Branchs.UnlockList;
end;
Branchs.Clear;

UpdateMyState();
TrevUserList.Items.Clear;
Me := nil;

if not DontAutoConnect then
begin
TimerAutoConnect.Interval := AutoConnectInterval * 1000;
TimerAutoConnect.Enabled := True;
end;

with MySockets.LockList do
try
for iLoop := Count - 1 downto 0 do
begin
try
MySocket := Items[iLoop];
MySocket.Free;
MySocket := nil;
except
end;
end;
finally
MySockets.UnlockList;
end;

if ClientTCP.Connected then
begin
ClientTCP.OnDisconnected := nil;
ClientTCP.Disconnect;
end;
end;

注销,退出都会运行这里
...全文
604 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
morrisyuan 2008-04-25
  • 打赏
  • 举报
回复
呵呵...我又发现新问题了,可惜没人教我.....

我把工具里的调试器里的语言异常里的indy eidclosed...exception 勾选后程序跑起来就没问题了,,,

只可惜,还是不能生成exe.....唉,无奈,无助
morrisyuan 2008-04-25
  • 打赏
  • 举报
回复
各位问题马上就要搞定了..大家再帮帮忙

if ClientTCP.Connected then
begin
ClientTCP.OnDisconnected := nil;
ClientTCP.Disconnect;
if ClientTCP.Connected then
showmessage('ok');
end;

我这样做卡是卡住了,但用F7继续运行下去,不会显示ok,说明它断了..就是会跳出那可恶的错误,试问我该怎么捕获它,不让它跳出来...

LoginTime := 0;
while LoginTime < 3 do
try
ClientTCP.Connect(8000);
break;
except
Inc(LoginTime);
end;

我发现在登录的时候如果不开服务端,它连不上也会跳出一个错误,检测到EIdSocketError,#10061 connect refused

一定得成功拦截住它们..
morrisyuan 2008-04-25
  • 打赏
  • 举报
回复
呵呵呵.自己搞好了..原来我的delphi水平还很水....

这个程序的工程里设置了输出路径..保存的地方我没看到


不过我还是很强大自已搞定了上面的那个问题..嘻嘻
daidai_____DD 2008-04-24
  • 打赏
  • 举报
回复
indy9 and indy10
morrisyuan 2008-04-24
  • 打赏
  • 举报
回复
二楼的朋友,谢谢你啊,不过我还没有搞定,,,,我的ClientTCP.IOHandler后面没有inputbuffer??????
ClientTCP后面有


我要是用这句ClientTCP.IOHandler.Close;放在你那try语句里,同样的错就跑到这句上面了,我用showmessage(INTTOSTR(ClientTCP.InputBuffer.Size));显示的是0 ,,,

再帮帮忙了,谢谢了...

顺便贴上这个unit

unit IdTCPClient;

interface

uses
Classes, IdStack,
IdException, IdGlobal, IdTCPConnection;

const
BoundPortDefault = 0;

type
TIdTCPClient = class(TIdTCPConnection)
protected
FBoundIP: string;
FBoundPort: Integer;
FBoundPortMax: Integer;
FBoundPortMin: Integer;
FHost: string;
FOnConnected: TNotifyEvent;
FPassword: string;
FPort: integer;
FUsername: string;
//
procedure SetHost(const Value: string); virtual;
procedure SetPort(const Value: integer); virtual;
procedure DoOnConnected; virtual;
//
property Username: string read FUsername write FUsername;
property Password: string read FPassword write FPassword;
public
procedure Connect(const ATimeout: Integer = IdTimeoutDefault); virtual;
function ConnectAndGetAll: string; virtual;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
//
property BoundPortMax: Integer read FBoundPortMax write FBoundPortMax;
property BoundPortMin: Integer read FBoundPortMin write FBoundPortMin;
published
property BoundIP: string read FBoundIP write FBoundIP;
property BoundPort: Integer read FBoundPort write FBoundPort default BoundPortDefault;
property Host: string read FHost write SetHost;
property OnConnected: TNotifyEvent read FOnConnected write FOnConnected;
property Port: integer read FPort write SetPort;
end;

implementation

uses
IdComponent, IdIOHandlerSocket, IdResourceStrings,
SysUtils;

{ TIdTCPClient }

procedure TIdTCPClient.Connect(const ATimeout: Integer = IdTimeoutDefault);
begin
// Do not call Connected here, it will call CheckDisconnect
if IOHandler <> nil then begin
if IOHandler.Connected then begin
raise EIdAlreadyConnected.Create(RSAlreadyConnected);
end;
end else begin
IOHandler := TIdIOHandlerSocket.Create(Self);
IOHandler.OnStatus := OnStatus;
FFreeIOHandlerOnDisconnect := True;
end;

try
IOHandler.Open;
ResetConnection;

// Socks support
IOHandler.ConnectClient(Host, Port, BoundIP, BoundPort, BoundPortMin, BoundPortMax, ATimeout);

if Assigned(Intercept) then begin
Intercept.Connect(Self);
end;
DoStatus(hsConnected, [Host]);
DoOnConnected;
except
// This will free IOHandler
DisconnectSocket;
raise;
end;
end;

function TIdTCPClient.ConnectAndGetAll: string;
begin
Connect; try
Result := AllData;
finally Disconnect; end;
end;

constructor TIdTCPClient.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBoundPort := BoundPortDefault;
end;

destructor TIdTCPClient.Destroy;
begin
inherited Destroy;
end;

procedure TIdTCPClient.DoOnConnected;
begin
if Assigned(OnConnected) then begin
OnConnected(Self);
end;
end;

procedure TIdTCPClient.SetHost(const Value: string);
begin
FHost := Value;
end;

procedure TIdTCPClient.SetPort(const Value: integer);
begin
FPort := Value;
end;

end.
morrisyuan 2008-04-24
  • 打赏
  • 举报
回复
我是在给人改代码,就这一个问题卡住了,能运行,不能生成exe..呵呵,路过的就帮一下我吧
sczyq 2008-04-23
  • 打赏
  • 举报
回复
if ClientTCP.Connected then
begin
ClientTCP.OnDisconnected := nil;
try
if ClientTCP.IOHandler <> nil then
if ClientTCP.IOHandler.InputBuffer <> nil then
if ClientTCP.IOHandler.InputBuffer.Size > 0 then
ClientTCP.IOHandler.InputBuffer.Clear;
finally
ClientTCP.Disconnect;
end;
end;


主要是要看缓冲区内有没有数据。

若空,肯定能停下。
若有数据就可能停不下来,所以要先清空缓冲区。
zhu_gx 2008-04-23
  • 打赏
  • 举报
回复
帮你顶一下

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧