예제 #1
0
        private void DoClient(ConnectClient client)
        {
            try
            {
                if (LogMessage != null)
                {
                    LogMessage("New connect");
                }

                using (var ss = new SessionServer())
                {
                    ss.LogMessage += LogMessage;
                    ss.Do(client);
                }
            }
            catch (Exception e)
            {
                var errorText = ExceptionUtil.ExceptionLog(e, "Server Exception");
                if (!(e is SocketException) && !(e.InnerException is SocketException))
                {
                    if (LogMessage != null)
                    {
                        LogMessage(errorText);
                    }
                }
            }
            //if (LogMessage != null) LogMessage("End connect");

            Interlocked.Decrement(ref _ActiveClientCount);
        }
예제 #2
0
        private void DoClient(ConnectClient client)
        {
            SessionServer session = null;
            string        addrIP  = ((IPEndPoint)client.Client.Client.RemoteEndPoint).Address.ToString();

            try
            {
                try
                {
                    if (Repository.CheckIsBanIP(addrIP))
                    {
                        Loger.Log("Abort connect BanIP " + addrIP);
                    }
                    else
                    {
                        Loger.Log($"New connect {addrIP} (connects: {ActiveClientCount})");
                        session = new SessionServer();
                        lock (Sessions)
                        {
                            Sessions.Add(session);
                        }
                        session.Do(client, SessionsAction);
                    }
                }
                catch (ObjectDisposedException)
                {
                    Loger.Log("Abort connect Relogin " + addrIP);
                }
                catch (Transfer.ConnectClient.ConnectSilenceTimeOutException)
                {
                    Loger.Log("Abort connect TimeOut " + addrIP);
                }
                catch (Exception e)
                {
                    if (!(e is SocketException) && !(e.InnerException is SocketException) &&
                        !(e is Transfer.ConnectClient.ConnectNotConnectedException) && !(e.InnerException is Transfer.ConnectClient.ConnectNotConnectedException))
                    {
                        ExceptionUtil.ExceptionLog(e, "Server Exception");
                    }
                }
                //if (LogMessage != null) LogMessage("End connect");
            }
            finally
            {
                Interlocked.Decrement(ref _ActiveClientCount);
                Loger.Log($"Close connect {addrIP}{(session == null ? "" : " " + session?.GetNameWhoConnect())} (connects: {ActiveClientCount})");
                try
                {
                    if (session != null)
                    {
                        session.Dispose();
                    }
                }
                catch
                { }
            }
        }