Q&A

  • [질문] 서버 종료가 않되는 문제
사용환경 : Delphi 2010 / Indy 10.5.5

Indy TcpServer와 TcpClient로 작성된 서버 프로그램과 클라이언트 프로그램이 있습니다.
서버 프로그램에서 연결된 클라이언트를 종료하고 서버도 종료하는 프로그램인데 제대로
실행이 않됩니다.
아래는 소스입니다.

<!--CodeS-->
procedure TFormServer.ButtonServerDisConnectClick(Sender: TObject);
var
  ClientList  : TList;
  ClientIndex : Integer;
begin
  try
    try
      //  서버에 연결된 클라이언트를 강제로 종료시킨다.
      ClientList  :=  IdTCPServer1.Contexts.LockList;
      for ClientIndex :=  0 to  ClientList.Count  - 1 do
        begin
         TIdContext( ClientList.Items[ClientIndex] ).Connection.Disconnect;
        end;
    finally
      IdTCPServer1.Contexts.UnlockList;
      ShowMessage(  '연결된 모든 클라이언트가 종료되었습니다.' );
    end;

    if  IdTCPServer1.Active = True  then
      begin
        IdTCPServer1.Active :=  False;  <---- 예외 발생 Socket Error # 10038
        ShowMessage(  '서버 프로그램이 종료되었습니다.' );
      end;
  except
    on  E:  Exception do
      begin

      end;
  end;
end;
<!--CodeE-->

실행은 잘 되다가도
IdTcpServer.Active := True;와 IdTcpServer.Active := False; 반복하다보면 무한루프에 걸립니다.
디버그를 걸어보면 Socket Error # 10038 예외오류가 나오면서 무한루핑이 도는데 어떻게 처리해야 하나요?
다른 글을 보니 10038 오류는 무시해도 된다고 합니다.
0  COMMENTS
  • profile cdrd
    2010/06/27 01:57
  • Views2450
    Likes0
    Comments0
    Reports0
  • Tag List
  • 목록으로