Microsoft MVP성태의 닷넷 이야기
비동기 소켓 close시 ObjectDisposedException 문제점 질문 있습니다.. [링크 복사], [링크+제목 복사],
조회: 21920
글쓴 사람
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)
5409민성11/16/202018507혹시 다른 질문이긴 한데요 [1]
5408최성재11/16/202015296vcpkg로 GDCM 내려받을 때 USE_VTK 설정하는 방법 [1]
5407민성11/11/202013697안녕하세요 yield return에 대해서 [1]
5406질문자11/10/202014738안녕하세요 wcf nettcpbinding의 timeout에 관해서 질문이 있습니다. [2]
5405민성11/9/202014703안녕하세요 이번에도 또 어려운 질문 같습니다. [1]
5404박진우11/6/202017223안녕하세요. SqlParameter 생성자 관련 질문 있습니다. [1]
5403민성11/5/202016845그리고 한가지만 죄송하지만 더 질문 드리겠습니다. [1]
5402민성11/5/202016512안녕하세요 책을 보고 질문하나만 드릴깨요 [2]
5401민성11/3/202015788안녕하세요 이번에도 질문 하나만 드리겠습니다. [2]
5400진우10/29/202015409SQL Server 관련 몇가지 문의 [2]
5399Wpf개...10/21/202015697Binding 된 항목의 갱신 시 간헐적 끊어짐 발생 문제. [2]
5397나그네10/15/202014789.net Core 3.1 에서 Entity Framework 와 ADO.NET 선택에 관해 여쭤봅니다. [2]
5396여정욱10/15/202014601CLR heap 관련 질문 2 [2]
5395여정욱10/14/202017121CLR heap 관련 질문 [2]
5394진우10/12/202021058닷넷코어 (닷넷5) winform wpf는 리눅스/맥에서도 가능한가요? [2]
5393김세용9/23/202016623C#에서 대량의 클래스를 빠르게 생성하는 방법이 없을까요? [6]
5392전경호9/22/202016083WPF에서 WindowsFormsHost의 메모리 누수 문제 때문에 문의드립니다. [1]파일 다운로드1
5391민성9/22/202015544안녕하세요 항상 감사드립니다. 하나 질문 드리겠습니다. [1]
5390alow...9/18/202018603System.AccessViolationException 보호된메모리 부분 예외처리 [1]
5389C# 8...9/18/202015634후위 증감 연산자 오버로딩 방법 좀 알려주세요 [4]
5388영귤9/17/202019311Nullable reference type 에 Non-nullable reference type 을 대입해도 경고가 발생하지 않습니다. [2]
5387하태9/17/202016281안녕하세요! 비동기 통신과 관련하여 질문하나만 드리겠습니다! [3]
5386박민웅9/16/202019239정성태 스승님 안녕하세요 !! [1]
5385영귤9/12/2020153703항 연산자에 ref 지원? [1]
5384guest9/10/202015230시작하세요! C# 8.0 프로그래밍 책에 오타가 있는 것 같습니다. [3]
5383민성9/8/202016959안녕하세요 자주 도움을 주셔서 감사드립니다. WPF에서 크롬 브라우저 삽입에 대하여 [1]
... 16  17  18  19  20  21  [22]  23  24  25  26  27  28  29  30  ...