Microsoft MVP성태의 닷넷 이야기
비동기 소켓 close시 ObjectDisposedException 문제점 질문 있습니다.. [링크 복사], [링크+제목 복사],
조회: 20456
글쓴 사람
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)
137정성태4/7/200510102            답변글 [답변]: [답변]: [답변]: c# .Net 에 대한 문의좀 ^^ [WinForm 에서 UserControl로 작성된 폼을 호출하려는데....]
138김용국4/7/20059051                답변글 [답변]: [답변]: [답변]: [답변]: c# .Net 에 대한 문의좀 ^^ [WinForm 에서 UserControl로 작성된 폼을 호출하려는데....]
139김용국4/11/20059578                    답변글 잘 해결 되었습니다... 감사합니다 [한줄답변]
129김용국3/31/200510534SmartClient 배포와 관련해서 무엇이 빠졌는지 좀 알려주시면 감사하겠습니다....!파일 다운로드2
130정성태3/31/20059683    답변글 [답변]: SmartClient 배포와 관련해서 무엇이 빠졌는지 좀 알려주시면 감사하겠습니다....!
131김용국4/1/20059158        답변글 [답변]: [답변]: SmartClient 배포와 관련해서 무엇이 빠졌는지 좀 알려주시면 감사하겠습니다....!
132정성태4/1/20059297            답변글 [답변]: [답변]: [답변]: SmartClient 배포와 관련해서 무엇이 빠졌는지 좀 알려주시면 감사하겠습니다....!
133김용국4/1/20059448                답변글 [답변]: [답변]: [답변]: [답변]: SmartClient 배포와 관련해서 무엇이 빠졌는지 좀 알려주시면 감사하겠습니다....!
126구정모3/31/200510752이홈의 효과는 어떻게???
128정성태3/31/20059876    답변글 [답변]: 이홈의 효과는 어떻게???
124배재현3/30/20059861Smart Client 문제로 이렇게 질문을 하나 올리게 됐습니다.^^;;
125정성태3/30/20059299    답변글 [답변]: Smart Client 문제로 이렇게 질문을 하나 올리게 됐습니다.^^;;
121안연준3/23/20059232이벤트 관련 문제
122정성태3/23/20059104    답변글 [답변]: 이벤트 관련 문제
120안연준3/23/20058939정성태님.... 오프라인 문제 질문 입니다. [1]
123정성태3/23/20059191    답변글 [답변]: 정성태님.... 오프라인 문제 질문 입니다. [1]
117정준명3/21/200510092COM+ 메소드 작성시...
118정성태3/29/20059648    답변글 [답변]: COM+ 메소드 작성시... [1]
109김용국3/18/200510619IE에 Docking된 WinFormControl내의 특정 메소드에 값을 보내기 .. 잘 되기는 하는데 한가지 문제가 ...
112정성태3/19/20059827    답변글 [답변]: IE에 Docking된 WinFormControl내의 특정 메소드에 값을 보내기 .. 잘 되기는 하는데 한가지 문제가 ...
113김용국3/19/20059762        답변글 [답변]: [답변]: IE에 Docking된 WinFormControl내의 특정 메소드에 값을 보내기 .. 잘 되기는 하는데 한가지 문제가 ...
114정성태3/19/20059844            답변글 [답변]: [답변]: [답변]: IE에 Docking된 WinFormControl내의 특정 메소드에 값을 보내기 .. 잘 되기는 하는데 한가지 문제가 ...
115김용국3/21/20059210                답변글 [답변]: [답변]: [답변]: [답변]: IE에 Docking된 WinFormControl내의 특정 메소드에 값을 보내기 .. 잘 되기는 하는데 한가지 문제가 ... [1]
119김용국3/22/20059171                    답변글 [답변]: 정상태님 아주 잘 해결 되었습니다.... 감사합니다!
108guest3/17/20059349닷넷 프레임워크 배포
111정성태3/19/20059739    답변글 [답변]: 닷넷 프레임워크 배포
... 91  92  [93]  94  95  96  97