Microsoft MVP성태의 닷넷 이야기
비동기 소켓 close시 ObjectDisposedException 문제점 질문 있습니다.. [링크 복사], [링크+제목 복사]
조회: 12920
글쓴 사람
C#초보
홈페이지
첨부 파일
 

        Socket listenSocket;

        private void tcpip_conBtn_Click(object sender, EventArgs e)
        {
            if (tcpip_conBtn.Text == "CONNECT")
            {
                tcpServer = new Server(10, 1024); // the maximum number of connectios , buffer size
                tcpServer.Initialize();
                tcpServer.Start(new IPEndPoint(IPAddress.Any, 5000));
                tcpip_textBox.Text += "TCP/IP SocketAsyncServer Start().... \r\n";
                tcpip_conBtn.Text = "DISCONNECT";
            }
            else
            {
                tcpip_conBtn.Text = "CONNECT";

                listenSocket .close();
              // tcpServer = null;
            }
        }


        public void Start(IPEndPoint localEndPoint)
        {
            // create the socket which listens for incoming connections
            listenSocket = new Socket(localEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            listenSocket.Bind(localEndPoint);
            listenSocket.Listen(100);

            StartAccept(null);
        }


        public void StartAccept(SocketAsyncEventArgs acceptEventArg)
        {
            if (acceptEventArg == null)
            {
                acceptEventArg = new SocketAsyncEventArgs();
                acceptEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(AcceptEventArg_Completed);
            }
            else
            {
                // socket must be cleared since the context object is being reused
                acceptEventArg.AcceptSocket = null;
            }

            m_maxNumberAcceptedClients.WaitOne();


            bool willRaiseEvent = listenSocket.AcceptAsync(acceptEventArg);

            if (!willRaiseEvent)
            {
                ProcessAccept(acceptEventArg);
            }

        }

        void AcceptEventArg_Completed(object sender, SocketAsyncEventArgs e)
        {
            ProcessAccept(e);
        }

  
버튼을 이용 연결 및 해제를 하려고 하는데요...
해제를 위해 버튼을 눌렀을때 소켓을 close() ( listen.close(); )하면..

StartAccept () 계속 호출 되는데요... 원래 이런건지요?? 아니면 소스가 잘못된건지요....
ObjectDisposedException 에러가 호출 되네요..
StartAccept () {
...
...
 bool willRaiseEvent = listenSocket.AcceptAsync(acceptEventArg); // 에러 부분...
...
...
...
}

조언좀 해주시면 감사하겠습니다...
참고로..
https://msdn.microsoft.com/ko-kr/library/system.net.sockets.socketasynceventargs(v=vs.110).aspx
예제를 참고하면서 구현하고 있습니다..








[최초 등록일: ]
[최종 수정일: 12/28/2016]


비밀번호

댓글 작성자
 



2016-12-30 06시31분
재현이 되는 최소한의 예제 프로젝트를 올려주세요.
정성태

... 16  [17]  18  19  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
5509한예지 donator6/3/20215759ExeccuteNonQuery 질문있습니다! [2]
5508최재남6/3/20216595마우스 이벤트 관련 질문 좀 드리겠습니다. [6]
5507한예6/2/20215755static과 스택오버플로우 질문있습니다. [5]파일 다운로드1
5506이창석6/1/20217166센서의 값을 받아서 PC를 통해 모니터링 하는 것을 만들고 있습니다. [1]
5505kss5/31/20215736.net5에서 소멸자가 어떻게 바뀐건가요? [1]
5503xing...5/24/20216119xingapinet 에 수정 요청 부탁 드립니다. [1]
5501한예지 donator5/23/20215892IProgress 사용법이 궁금합니다. [2]
5500한예ㅈ5/23/20217776비동기 코드 흐름 질문있습니다. [3]
5498곰장어5/21/20215637List에 static 변수를 추가했을때의 궁금증 [3]파일 다운로드1
5497지평선5/20/20216876윈도우 배율을 알 수 있을까요? [1]
5496cs린이5/20/20215512C# 8.0 질문입니다. [2]파일 다운로드6
5495Natie5/13/20215034객체를 생성과 동시에 초기화 하는 방법 [1]
5494지예예지5/13/20217306비동기 코드 흐름이 궁금합니다! [2]
5493xing...5/6/20215210xing api XQCSPAT00600 질문입니다 [4]파일 다운로드1
5492한예지 donator5/5/20215285FromCurrentSynchronizationContext 관련 코드 질문있습니다! [2]
5491조우성5/4/20219726WinForm과 WPF의 성능차이 비교한 자료가 있을까요? [4]
5490한예지 donator5/3/20216089UI 스레드의 Invoke 질문있습니다. [4]
5489저누4/28/20216662시작하세요 C# 9.0, 225페이지 구조체 관련 질문드립니다. [2]
5488종범4/27/20216910C# 비동기 함수 async, await 와 Task의 관계에 대해 질문 드립니다. [6]
5487진우4/27/20216288C# 엑셀 자동화 성능 향상 문의 [2]
5486지나가던...4/26/20215838닷넷 구현 코드 관련 질문 [2]
5485이재원4/17/20216216교재 315페이지 내용 질문 [3]
5484Syong4/16/20219747윈폼 기반의 응용프로그램 dll 참조와 32,64bit 빌드 관련 문의 [4]
5483한예지 donator4/15/20215263익명 형식과 var 관계 질문 있습니다. [2]
5482질문4/13/20217056WPF를 위한 MVVM toolkit 선택과 관련한 문의드립니다. [4]
5480한예지 donator4/5/20217357GetHashCode 질문있습니다! [2]
... 16  [17]  18  19  20  21  22  23  24  25  26  27  28  29  30  ...