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

... [91]  92  93  94  95  96  97 
NoWriterDateCnt.TitleFile(s)
183정성태5/9/20059441    답변글 [답변]: // 꼭쫌 답변해 주세요~~~클라이언트 서버 ... 내용, 이점 들...
180최성우5/7/20059905[Q] POST 형식의 데이터 훅킹?
182정성태5/9/200510517    답변글 [답변]: [Q] POST 형식의 데이터 훅킹?
190최성우5/10/20059544        답변글 [답변]: [답변]: [Q] POST 형식의 데이터 훅킹?
177최정희5/4/200510062네트워크 케이블의 연결상태
178정성태5/4/200510204    답변글 [답변]: 네트워크 케이블의 연결상태 [1]
188최정희5/10/20059677        답변글 [답변]: [답변]: 네트워크 케이블의 연결상태
189정성태5/10/20059853            답변글 [답변]: [답변]: [답변]: 네트워크 케이블의 연결상태 [2]
191최정희5/11/20059501                답변글 [답변]: [답변]: [답변]: [답변]: 네트워크 케이블의 연결상태 [1]
175안연준5/3/20059891IE 제어에 대한 궁금 증 ㅡ,.ㅡ;;
179정성태5/4/200510562    답변글 [답변]: IE 제어에 대한 궁금 증 ㅡ,.ㅡ;;
168안연준5/2/20059944[Database] Connection Error파일 다운로드1
169정성태5/2/200510078    답변글 [답변]: [Database] Connection Error
170안연준5/2/20059633        답변글 [답변]: [답변]: 계속 에러가 똑같애요
171정성태5/2/200510333            답변글 [답변]: [답변]: [답변]: 계속 에러가 똑같애요
172안연준5/2/200510124                답변글 [답변]: [답변]: [답변]: [답변]: 계속 에러가 똑같애요파일 다운로드1
173정성태5/2/20059893                    답변글 [답변]: [답변]: [답변]: [답변]: [답변]: 계속 에러가 똑같애요
174안연준5/3/20059836                        답변글 [답변]: [답변]: [답변]: [답변]: [답변]: [답변]: 계속 에러가 똑같애요
165장희석4/22/200510480[질문]ASP에서 ATL 서버 컴퍼넌트로 바이너리 데이타 전달하기
167정성태4/29/200510308    답변글 [답변]: [질문]ASP에서 ATL 서버 컴퍼넌트로 바이너리 데이타 전달하기
160카심4/21/20059887Internet Explorer 에서의 닷넷 Smart Client 개발
163정성태4/22/20059808    답변글 [답변]: Internet Explorer 에서의 닷넷 Smart Client 개발
159신대철4/21/20059575자동 로긴 프로그램
162정성태4/22/20059593    답변글 [답변]: 자동 로긴 프로그램
166신대철4/22/20059276        답변글 [답변]: [답변]: 자동 로긴 프로그램파일 다운로드1
157이용휘4/20/20059274w3ip를 통해서 윈도우 미디어 화을을 올려놓을 서버..
... [91]  92  93  94  95  96  97