Example #1
0
        private void AcceptCallback(IAsyncResult asyncResult)
        {
            Socket socket = null;

            try
            {
                socket = Sock.EndAccept(asyncResult);
            }
            catch (ObjectDisposedException) { return; }
            catch (Exception ex)
            {
                EventProvider.ExecuteErrorHandler(ex, SocketErrorLocation.EndStart);
                return;
            }

            TcpReceiveSocket receiveSocket = new TcpReceiveSocket(socket, SocketSide.Client, EventProvider);

            if (receiveSocket.Start())
            {
                TcpClientSockets.Add(receiveSocket);
                TcpClientSockets.TrimExcess();
            }

            EventProvider.ExecuteHandshakeHandler(((IPEndPoint)socket.RemoteEndPoint).Address, receiveSocket);

            Sock.BeginAccept(AcceptCallback, null);
        }
Example #2
0
 public override bool Start()
 {
     try
     {
         Sock.BeginAccept(AcceptCallback, null);
         State = SocketState.Started;
     }
     catch (Exception ex)
     {
         EventProvider.ExecuteErrorHandler(ex, SocketErrorLocation.BeginStart);
         return(false);
     }
     return(true);
 }