Microsoft MVP성태의 닷넷 이야기
비동기 소켓 close시 ObjectDisposedException 문제점 질문 있습니다.. [링크 복사], [링크+제목 복사],
조회: 13043
글쓴 사람
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분
재현이 되는 최소한의 예제 프로젝트를 올려주세요.
정성태

... 46  47  48  49  50  51  52  53  54  55  [56]  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
1238(non...3/13/201411989(글쓴이의 요청으로 삭제합니다.) [2]
1237(non...3/11/201412099(글쓴이의 요청으로 삭제합니다.) [2]
1236(non...3/11/201412979(글쓴이의 요청으로 삭제합니다.) [2]
1235(non...3/10/201412124(글쓴이의 요청으로 삭제합니다.) [2]
1234(non...3/10/201414145(글쓴이의 요청으로 삭제합니다.) [3]
1233(non...3/9/201412275(글쓴이의 요청으로 삭제합니다.) [4]
1232(non...3/8/201411339(글쓴이의 요청으로 삭제합니다.) [2]
1231(non...3/7/201412656(글쓴이의 요청으로 삭제합니다.) [9]
1230POCO3/7/201412998쓰레드 안에서 DependencyProperty get, set시 또 다른 스레드 오류.. [1]
1229(non...3/6/201412730(글쓴이의 요청으로 삭제합니다.) [11]
1228POCO3/6/201411241안녕하세요. 질문이 있습니다. [1]
1226김형진3/4/201419818안녕하세요 windows azure에 관해 질문했던 사람입니다. [2]
1224(non...3/3/201415954(글쓴이의 요청으로 삭제합니다.) [11]
1223sadf...3/3/201411536아래 질문에 답변 감사드립니다. 한가지 더 궁금한점이 있어 질문드립니다. [1]
1222(non...3/2/201412390(글쓴이의 요청으로 삭제합니다.) [4]
1221(non...3/1/201412444(글쓴이의 요청으로 삭제합니다.) [2]
1220Until2/28/201410974질문드립니다. [1]
1219이성환2/28/201410656string.Join()과 Enumerable.Aggregate()의 차이가 궁금합니다. [2]파일 다운로드1
1218김형진2/25/201412111안녕하세요. window azure에 대해서 질문이 있어서 문의 드립니다 [4]
1217(non...2/23/201412557(글쓴이의 요청으로 삭제합니다.) [1]
1215아리수2/20/201416100C# 공부하면서 WPF에 대한 질문. [2]
1214조광훈2/20/201414346IIS8 응용프로그램 풀 관련 질문 드립니다. [2]파일 다운로드1
1213김태훈2/17/201411246가상화 프로그램 질문입니다. [1]파일 다운로드1
1212조광훈2/13/201410399ISAPI 필터에서 커스텀 헤더 정보 추가 [1]파일 다운로드1
1211조광훈2/12/201413823isapi 필터 로드 오류 [2]
1208박지호2/9/201417163[오타] 시작하세요 C# 프로그래밍 p.267 ~ 350 [1]
... 46  47  48  49  50  51  52  53  54  55  [56]  57  58  59  60  ...