@@ -60,7 +60,7 @@ public class Connection : Communication, IDisposable
6060 private bool _isSendingToServer = false ;
6161 private bool _isStarted ;
6262
63- public delegate bool ReceivedMessageEventHandler ( byte [ ] data ) ;
63+ public delegate void ReceivedMessageEventHandler ( byte [ ] data ) ;
6464
6565 public event ReceivedMessageEventHandler OnReceivedClientMessage ;
6666 public event ReceivedMessageEventHandler OnReceivedServerMessage ;
@@ -555,6 +555,10 @@ private void BeginGetContextCallback(IAsyncResult ar)
555555
556556 _httpListener . BeginGetContext ( new AsyncCallback ( BeginGetContextCallback ) , _httpListener ) ;
557557 }
558+ catch ( ObjectDisposedException )
559+ {
560+ // This exception can occur if Stop() is called.
561+ }
558562 catch ( Exception ex )
559563 {
560564 Console . WriteLine ( ex . ToString ( ) ) ;
@@ -584,6 +588,10 @@ private void BeginAcceptTcpClientCallback(IAsyncResult ar)
584588
585589 _tcpListener . BeginAcceptSocket ( new AsyncCallback ( BeginAcceptTcpClientCallback ) , _tcpListener ) ;
586590 }
591+ catch ( ObjectDisposedException )
592+ {
593+ // This exception can occur if Stop() is called.
594+ }
587595 catch ( Exception ex )
588596 {
589597 Console . WriteLine ( ex . ToString ( ) ) ;
@@ -808,6 +816,10 @@ private void BeginReceiveServerCallback(IAsyncResult ar)
808816
809817 _serverSocket . BeginReceive ( _serverInMessage . GetBuffer ( ) , 0 , 2 , SocketFlags . None , new AsyncCallback ( BeginReceiveServerCallback ) , 1 ) ;
810818 }
819+ catch ( ObjectDisposedException )
820+ {
821+ // This exception can occur if Stop() is called.
822+ }
811823 catch ( SocketException )
812824 {
813825 // This exception can happen if the server, forcefully, closes the connection.
0 commit comments