用idTCPserver写的server程序退出时,出现异常的问题(底下有client,且没有断开连接);问怎样处理可以避免出现异常!!
解决方案 »
- Procedure pointer types are always incompatible with method pointer types. Th
- listview中怎么得到选中的多行数据
- ★★Delphi 2004-03专家榜★★
- 关于SQL SERVER 2000 数据库还原的问题请各位高手帮忙
- delphi连接oracle 怎么样连接?
- 数据库别名
- 如何用程序遍历一个数组的全排列?谢谢!
- 还是RAVE打印时弹出的窗口?!请RAVE高手帮帮忙.
- 如何利用serversocket和clientsocket实现文件传输?
- 十万火急,我遇上两个奇怪的问题。答者重谢。
- 关于listview
- 请教!service application 运行大约10秒就自己退出的问题.
需要断开时,可调用如下的代码:
TIdPeerThread(lcThread).Connection.Disconnect;另外,你说的这种异常好像只是在调试的时候才会出现吧??
如果是那样的话,可以不用理它。
用外国程序员的说法就是,那是正常的异常!!
var
i: Integer;
LListenerThread: TIdListenerThread;
begin
// SG 28/11/01: removed the "try..finally FActive := AValue; end;" wrapper
// SG 28/11/01: It cause the component to be locked in the "active" state, even if
// SG 28/11/01: the socket couldn't be bound.
if (not (csDesigning in ComponentState)) and (FActive <> AValue)
and (not (csLoading in ComponentState)) then begin
if AValue then begin
// InitializeCommandHandlers must be called only at runtime, and only after streaming
// has occured. This used to be in .Loaded and that worked for forms. It failed
// for dynamically created instances and also for descendant classes.
if not FCommandHandlersInitialized then begin
FCommandHandlersInitialized := True;
InitializeCommandHandlers;
end;
// Set up bindings
if Bindings.Count = 0 then begin
Bindings.Add;
end; // Set up ThreadMgr
ThreadMgr.ThreadClass := ThreadClass; // Setup IOHandler if not Assigned(FIOHandler) then begin
IOHandler := TIdServerIOHandlerSocket.Create(self);
FImplicitIOHandler := true;
end;
// Update reply texts for "global" replies
ReplyTexts.UpdateText(ReplyUnknownCommand);
ReplyTexts.UpdateText(MaxConnectionReply);
// Set up listener threads IOHandler.Init;
i := 0;
try
while i < Bindings.Count do begin
with Bindings[i] do begin
AllocateSocket;
if (FReuseSocket = rsTrue) or ((FReuseSocket = rsOSDependent) and (GOSType = otLinux))
then begin
SetSockOpt(Id_SOL_SOCKET, Id_SO_REUSEADDR, PChar(@Id_SO_True), SizeOf(Id_SO_True));
end;
Bind;
end;
Inc(i);
end;
except
Dec(i); // the one that failed doesn't need to be closed
while i >= 0 do begin
Bindings[i].CloseSocket;
Dec(i);
end;
FActive := True;
SetActive(False); // allow descendants to clean up
raise;
end;
FListenerThreads := TThreadList.Create;
for i := 0 to Bindings.Count - 1 do begin
Bindings[i].Listen(FListenQueue);
LListenerThread := TIdListenerThread.Create(Self, Bindings[i]);
FListenerThreads.Add(LListenerThread);
LListenerThread.Start;
end;
FActive := True; // fixed by Liu Yang 2004.7.24 end else begin
TerminateListenerThreads;
FActive := false; // fixed by Liu Yang 2004.7.24
// Tear down ThreadMgr
try
TerminateAllThreads;
finally
if ImplicitThreadMgr and TIdThreadSafeList(Threads).IsCountLessThan(1) then begin // DONE -oAPR: BUG! Threads still live, Mgr dead ;-(
FreeAndNil(FThreadMgr);
FImplicitThreadMgr := False;
end;
end;//tryf
end;
end;
FActive := AValue;
end;http://lysoft.7u7.net
to liuyang,请问有不改indy源程序的方法吗?
比如我可以在自己的程序中,先将连接线程去掉可以吗,怎么做???