请问一下这个问题一般都是什么情况造成的......我该从哪几个方面入手找错误源.....错误提示如附件图片所示:
工程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;注销,退出都会运行这里
工程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;注销,退出都会运行这里
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;
主要是要看缓冲区内有没有数据。
若空,肯定能停下。
若有数据就可能停不下来,所以要先清空缓冲区。
ClientTCP后面有
我要是用这句ClientTCP.IOHandler.Close;放在你那try语句里,同样的错就跑到这句上面了,我用showmessage(INTTOSTR(ClientTCP.InputBuffer.Size));显示的是0 ,,,再帮帮忙了,谢谢了...顺便贴上这个unitunit IdTCPClient;interfaceuses
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;implementationuses
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.
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一定得成功拦截住它们..
不过我还是很强大自已搞定了上面的那个问题..嘻嘻