Ejemplo n.º 1
0
        /// <summary>
        /// The callback for BeginAccept.
        /// </summary>
        /// <param name="asyncResult">The asynchronous result.</param>
        private void Handle_Accept(IAsyncResult asyncResult)
        {
            try
            {
                Client <T> client = Socket.EndAccept(asyncResult);
                if (client.Socket.Connected)
                {
                    client.ShouldHandleDisconnect = ShouldHandleDisconnect;
                    if (OnConnect != null)
                    {
                        client.OnDisconnect   = OnDisconnect;
                        client.ControllerCall = _controllerCall;

                        OnConnect.BeginInvoke(client, null, null);
                    }
                }

                Socket.BeginAccept(Handle_Accept, null);
            }
            catch (Exception e)
            {
                                #if DEBUG
                                #if TRACE
                ErrorLogger.Log(StackTracing.GetCurrentMethod().Name, e);
                                #else
                ErrorLogger.Log(Messages.Errors.FATAL_NETWORK_ERROR_TITLE, e);
                                #endif
                if (e is SocketException)
                {
                    Stop();
                }
                                #else
                if (e is SocketException)
                {
                    Stop();
                    Global.Message(Messages.Errors.FATAL_NETWORK_ERROR_MSG);
                }
                Global.Message(e.ToString());
                                #endif
            }
        }