Пример #1
0
        /// <summary> Closes this <see cref="Connection"/>, sends a <see cref="CloseRequest"/> to the remote <see cref="Connection"/>, and writes all remaining queued <see cref="Packet"/> s to the network (they are received before the <see cref="CloseRequest"/> will be handled). </summary>
        /// <param name="closeReason">    The reason for the <see cref="Connection"/> closing. </param>
        /// <param name="callCloseEvent"> If this <see cref="Connection"/> instance should call its <see cref="Connection"/> event. </param>
        public void Close(CloseReason closeReason, bool callCloseEvent = false)
        {
            //Check if this connection is already dead. If so, there is no need to
            //handle an exception or anything else.
            if (!IsAlive)
            {
                return;
            }

            try
            {
                Send(new CloseRequest(closeReason));
                WriteSubWork(); //Force to write the remaining packets.
            }
            catch (Exception exception)
            {
                Logger.Log($"Couldn't send a close-message '{closeReason.ToString()}' to the endpoint.", exception, LogLevel.Warning);
            }

            // always inform the internal network lib about the lost connection.
            networkConnectionClosed?.Invoke(closeReason, this);

            if (callCloseEvent)
            {
                connectionClosed?.Invoke(closeReason, this);
            }

            // close all sockets (throw an exception during any read or write operation)
            CloseSocket();

            // singal all threads to exit their routine.
            threadCancellationTokenSource.Cancel();
        }
Пример #2
0
        private void appServer_NewSessionClosed(AppSession session, CloseReason aaa)
        {
            LogHelper.Log.Info($"服务端 失去 来自客户端的连接" + session.SessionID + aaa.ToString());
            var count = appServer.GetAllSessions().Count();

            LogHelper.Log.Info("连接数量 " + count);
        }
Пример #3
0
 //客户端断开
 void app_SessionClosed(MySession session, CloseReason value)
 {
     this.Dispatcher.BeginInvoke(new Action(() =>
     {
         txbReceive.AppendText($"客户端{session.SessionID}已断开,原因:{value.ToString()}" + '\n');
     }));
 }
        public async Task CloseAsync(PartitionContext context, CloseReason reason)
        {
            try
            {
                // TraceIn
                TraceEventSource.Log.TraceIn();

                // Trace Open Partition
                TraceEventSource.Log.ClosePartition(context.EventHubPath,
                                                    context.ConsumerGroupName,
                                                    context.Lease.PartitionId,
                                                    reason.ToString());

                if (reason == CloseReason.Shutdown)
                {
                    await context.CheckpointAsync();
                }
            }
            catch (Exception ex)
            {
                // Trace Exception
                TraceEventSource.Log.TraceError(ex.Message, ex.InnerException?.Message ?? string.Empty);
            }
            finally
            {
                // TraceOut
                TraceEventSource.Log.TraceOut();
            }
        }
Пример #5
0
        /// <summary>
        /// Closes this <see cref="Connection"/>, sends a <see cref="CloseRequest"/> to the remote <see cref="Connection"/>,
        /// and writes all remaining queued <see cref="Packet"/>s to the network (they are received before the <see cref="CloseRequest"/>
        /// will be handled).
        /// </summary>
        /// <param name="closeReason">The reason for the <see cref="Connection"/> closing.</param>
        /// <param name="callCloseEvent">If this <see cref="Connection"/> instance should call its <see cref="Connection"/> event.</param>
        public void Close(CloseReason closeReason, bool callCloseEvent = false)
        {
            //Check if this connection is already dead. If so, there is no need to
            //handle an exception or anything else.
            if (!IsAlive)
            {
                return;
            }

            try
            {
                Send(new CloseRequest(closeReason), true);
                WriteSubWork(); //Force to write the remaining packets.
            }
            catch (Exception exception)
            {
                Logger.Log($"Couldn't send a close-message '{closeReason.ToString()}' to the endpoint.", exception, LogLevel.Warning);
            }

            if (callCloseEvent)
            {
                connectionClosed?.Invoke(closeReason, this);
            }

            writeStreamThread.AbortSave();
            readStreamThread.AbortSave();
            invokePacketThread.AbortSave();
            CloseSocket();
        }
Пример #6
0
        protected override void OnSessionClosed(PlayerSession session, CloseReason reason)
        {
            base.OnSessionClosed(session, reason);
            if (!session.IsLogin)
            {
                return;
            }
            var package = new G2G_ToGameDisconnect()
            {
                Reason = reason.ToString()
            };

            using (var ms = new MemoryStream())
            {
                Serializer.Serialize(ms, package);
                var packageData = ms.ToArray();

                var    converter = EndianBitConverter.Big;
                byte[] sendData  = new byte[packageData.Length + 4];
                converter.CopyBytes((int)CMD_G2G.ToGameDisconnect, sendData, 0);
                Buffer.BlockCopy(packageData, 0, sendData, 4, packageData.Length);

                Push2GameServer(session, sendData);
            }

            PlayerSession savedSession;

            ManagedSessionByNetHandle.TryRemove(session.NetHandle, out savedSession);
        }
Пример #7
0
 private static void OnClosed(WebSocketSession session, CloseReason value)
 {
     Log.Info("Device Closed  [ ID:" + session.SessionID + "  Reason:" + value.ToString() + " ]");
     Console.Title = ("Online " + SessionPool.DevicesCount() + " User");
     Login.LoginOut(session.UserId);
     SessionPool.Remove(session);
 }
 public async Task CloseAsync(PartitionContext context, CloseReason reason)
 {
     Trace.TraceInformation(string.Format("EventProcessor Shuting Down.  Partition '{0}', Reason: '{1}'.", this.partitionContext.Lease.PartitionId, reason.ToString()));
     if (reason == CloseReason.Shutdown)
     {
         await context.CheckpointAsync();
     }
 }
Пример #9
0
            public Task CloseAsync(PartitionContext context, CloseReason reason)
            {
                // signal cancellation for any in progress executions
                _cts.Cancel();

                _logger.LogDebug(GetOperationDetails(context, $"CloseAsync, {reason.ToString()}"));
                return(Task.CompletedTask);
            }
Пример #10
0
        void OnClosed(ClientSession session, CloseReason reason)
        {
            MainLogger.Info(string.Format("세션 번호 {0} 접속해제: {1}", session.SessionID, reason.ToString()));

            //TODO:로그인을 성공한 경우라면 게임서버에 통보해야 한다.

            ClientSessionMgr.ColesdSession(session);
        }
Пример #11
0
        void OnClosed(ClientSession session, CloseReason reason)
        {
            MainLogger.Info(string.Format("세션 번호 {0} 접속해제: {1}", session.SessionID, reason.ToString()));

            var packet = ServerPacketData.MakeNTFInConnectOrDisConnectClientPacket(false, session.SessionID);

            Distribute(packet);
        }
Пример #12
0
 async Task IEventProcessor.CloseAsync(PartitionContext context, CloseReason reason)
 {
     Console.WriteLine(string.Format("Processor Shuting Down.  Partition '{0}', Reason: '{1}'.", context.Lease.PartitionId, reason.ToString()));
     if (reason == CloseReason.Shutdown)
     {
         await context.CheckpointAsync();
     }
 }
Пример #13
0
 public async Task CloseAsync(PartitionContext context, CloseReason reason)
 {
     if (!WebJobsHelper.RunAsWebJobs)
         Console.WriteLine(string.Format("Processor Shuting Down. Partition '{0}', Reason: '{1}'.",
             partitionContext.Lease.PartitionId, reason.ToString()));
     if (reason == CloseReason.Shutdown)
         await context.CheckpointAsync();
 }
Пример #14
0
        void OnClosed(NetworkSession session, CloseReason reason)
        {
            Console.WriteLine("{0} SessionID {1} DisconnectReason : {2}  thdID({3})",
                              session.Address().ToString(),
                              session.SessionID, reason.ToString(), Thread.CurrentThread.ManagedThreadId);

            // NetServer 내부적으로 관리를 위해 클라이언트 연결종료시점에 필요한 작업
            net.OnLeave(session);
        }
        public Task CloseAsync(PartitionContext context, CloseReason reason)
        {
            Trace.TraceInformation("Processor Shuting Down.  Partition '{0}', Reason: '{1}'.", this.Context.Lease.PartitionId, reason.ToString());

            this.IsClosed = true;
            this.OnProcessorClosed();

            return context.CheckpointAsync();
        }
Пример #16
0
        void appServer_SessionClosed(ProtocolSession session, CloseReason value)
        {
            Console.Write(DateTime.Now.ToString() + "   ");
            Console.WriteLine("断开了 " + session.SessionID + " " + value.ToString());
            dic.Remove(session.SessionID);
            ReceiveController.SessionClose(session.SessionID);

            testIds.Remove(session.SessionID);
        }
        async Task IEventProcessor.CloseAsync(PartitionContext context, CloseReason reason)
        {
            _logger.EventProcessorStopped(reason.ToString(), context.EventHubPath, context.ConsumerGroupName, context.Lease.PartitionId, context.Lease.Offset, context.Lease.Epoch);

            if (reason == CloseReason.Shutdown)
            {
                await context.CheckpointAsync();
                _logger.EventProcessorCheckpointed(context.EventHubPath, context.ConsumerGroupName, context.Lease.PartitionId, context.Lease.Offset, context.Lease.Epoch);
            }
        }
Пример #18
0
 public async Task CloseAsync(PartitionContext context, CloseReason reason)
 {
     Trace.TraceWarning("SimpleEventProcessor CloseAsync.  Partition '{0}', Reason: '{1}'.",
         this.partitionContext.Lease.PartitionId, reason.ToString());
     _run = false;
     if (reason == CloseReason.Shutdown)
     {
         await context.CheckpointAsync();
     }
 }
        public async Task CloseAsync(PartitionContext context, CloseReason reason)
        {
            Console.WriteLine(string.Format("StorageProcessor closing. Partition '{0}', Reason: '{1}'.", context.Lease.PartitionId, reason.ToString()));

            _account = null;

            if (reason == CloseReason.Shutdown)
            {
                await context.CheckpointAsync();
            }
        }
Пример #20
0
        void OnClosed(ClientSession session, CloseReason reason)
        {
            WriteLog(string.Format("세션 번호 {0} 접속해제: {1}", session.SessionID, reason.ToString()), LOG_LEVEL.INFO);


            var packet = ServerPacketData.MakeNTFInConnectOrDisConnectClientPacket(false, session.SessionID, session.SessionIndex);

            Distributor.DistributeCommon(false, packet);

            session.FreeSessionIndex(session.SessionIndex);
        }
        public virtual async Task CloseAsync(PartitionContext context, CloseReason reason)
        {
            Trace.WriteLine(string.Format("Processor Shuting Down.  Partition '{0}', Reason: '{1}'."
                                            , this.PartitionContext.Lease.PartitionId
                                            , reason.ToString()));

            if (reason == CloseReason.Shutdown)
            {
                await context.CheckpointAsync();
            }
        }
        Task IEventProcessor.CloseAsync(PartitionContext context, CloseReason reason)
        {
            var props = new Dictionary <string, string>
            {
                { "Partition", context.Lease.PartitionId },
                { "Offset", context.Lease.Offset },
                { "Reason", reason.ToString() }
            };

            _logger.LogInformation("EventHubReader/Closed", props);
            return(Task.FromResult <object>(null));
        }
Пример #23
0
 //session关闭到达这里
 protected override void OnSessionClosed(CloseReason reason)
 {
     this.isSessionAlive = false;
     Console.WriteLine(TAG + "OnSessionClosed " + reason.ToString());
     //如果该session已经链接并且是controlsession,只要session断掉之后
     //就进行初始化
     if (isSessionOnline && isSessionLogin)
     {
         MyAppServer.onSessionClosed();
     }
     base.OnSessionClosed(reason);
 }
Пример #24
0
        public Task CloseAsync(PartitionContext context, CloseReason reason)
        {
            this.telemetry.TrackTrace(
                $"ClosePartition {context.Lease.PartitionId}: {reason}", 
                SeverityLevel.Information,
                new Dictionary<string, string>
                {
                    { "PartitionId", context.Lease.PartitionId },
                    { "Reason", reason.ToString() }
                });

            this.perfCounters.EventHub_Processors.Decrement();

            return Task.FromResult(true);
        }
        public Task CloseAsync(PartitionContext context, CloseReason reason)
        {
            this.telemetry.TrackTrace(
                $"ClosePartition {context.Lease.PartitionId}: {reason}",
                SeverityLevel.Information,
                new Dictionary <string, string>
            {
                { "PartitionId", context.Lease.PartitionId },
                { "Reason", reason.ToString() }
            });

            this.perfCounters.EventHub_Processors.Decrement();

            return(Task.FromResult(true));
        }
Пример #26
0
        public async Task CloseAsync(PartitionContext context, CloseReason reason)
        {
            try
            {
                // Trace Open Partition
                ServiceEventSource.Current.ClosePartition(context.EventHubPath,
                                                          context.ConsumerGroupName,
                                                          context.Lease.PartitionId,
                                                          reason.ToString());

                if (reason == CloseReason.Shutdown)
                {
                    await context.CheckpointAsync();
                }
            }
            catch (Exception ex)
            {
                // Trace Exception
                ServiceEventSource.Current.Message(ex.Message);
            }
        }
Пример #27
0
        protected override void OnSessionClosed(PlayerSession session, CloseReason reason)
        {
            base.OnSessionClosed(session, reason);

            var package = new G2G_ToGameDisconnect()
            {
                Reason = reason.ToString()
            };

            using (var ms = new MemoryStream())
            {
                Serializer.Serialize(ms, package);
                var packageData = ms.ToArray();

                var    converter = EndianBitConverter.Big;
                byte[] sendData  = new byte[packageData.Length + 4];
                converter.CopyBytes((int)CMD_G2G.ToGameDisconnect, sendData, 0);
                Buffer.BlockCopy(packageData, 0, sendData, 4, packageData.Length);
                Push2GameServer(session, sendData);
            }
#if Log
            Console.WriteLine("{0}:one session close", DateTime.Now);
#endif
        }
Пример #28
0
 static void appServer_SessionClosed(WebSocketSession session, CloseReason reason)
 {
     Console.WriteLine("Somebody left " + reason.ToString());
 }
Пример #29
0
 static void wsServer_SessionClosed(WebSocketSession session, CloseReason value)
 {
     Console.WriteLine("wsServer_SessionClosed. SessionCount=["
                       + session.AppServer.SessionCount.ToString() + "] CloseReason=[" + value.ToString() + "]");
 }
Пример #30
0
 void OnClosed(NetworkSession2 session, CloseReason reason)
 {
     DevLog.Write(string.Format("세션 번호 {0} 접속해제: {1}", session.SessionID, reason.ToString()), LOG_LEVEL.INFO);
 }
 public async Task CloseAsync(PartitionContext context, CloseReason reason)
 {
     Trace.TraceWarning(string.Format("SimpleVehicleEventConsumer CloseAsync.  Partition '{0}', Reason: '{1}'.", this.partitionContext.Lease.PartitionId, reason.ToString()));
     if (reason == CloseReason.Shutdown)
     {
         await context.CheckpointAsync();
     }
 }
 void OnClosed(ClientSession session, CloseReason reason)
 {
     MainLogger.Info(string.Format("세션 번호 {0} 접속해제: {1}", session.SessionID, reason.ToString()));
 }
Пример #33
0
 public async Task CloseAsync(PartitionContext context, CloseReason reason)
 {
     Console.WriteLine(string.Format("Processor close.  Partition '{0}', Reason: '{1}'.", context.Lease.PartitionId, reason.ToString()));
     if (reason == CloseReason.Shutdown)
     {
         await context.CheckpointAsync();
     }
 }
        public Task CloseAsync(PartitionContext context, CloseReason reason)
        {
            Console.WriteLine(string.Format("EntityProcessor closing. Partition '{0}', Reason: '{1}'.", context.Lease.PartitionId, reason.ToString()));

            return Task.FromResult<object>(null);
        }
Пример #35
0
 private static void AppServer_SessionClosed(AppSession session, CloseReason value)
 {
     Console.WriteLine(string.Format("{0}断开连接", session.SessionID));
     session.Send(value.ToString());
 }
Пример #36
0
        public async Task CloseAsync(CloseReason reason)
        {
            ProcessorEventSource.Log.PartitionPumpCloseStart(this.Host.HostName, this.PartitionContext.PartitionId, reason.ToString());
            this.PumpStatus = PartitionPumpStatus.Closing;
            try
            {
                this.cancellationTokenSource.Cancel();

                await this.OnClosingAsync(reason).ConfigureAwait(false);

                if (this.Processor != null)
                {
                    using (await this.ProcessingAsyncLock.LockAsync().ConfigureAwait(false))
                    {
                        // When we take the lock, any existing ProcessEventsAsync call has finished.
                        // Because the client has been closed, there will not be any more
                        // calls to onEvents in the future. Therefore we can safely call CloseAsync.
                        ProcessorEventSource.Log.PartitionPumpInvokeProcessorCloseStart(this.Host.HostName, this.PartitionContext.PartitionId, reason.ToString());
                        await this.Processor.CloseAsync(this.PartitionContext, reason).ConfigureAwait(false);

                        ProcessorEventSource.Log.PartitionPumpInvokeProcessorCloseStop(this.Host.HostName, this.PartitionContext.PartitionId);
                    }
                }
            }
            catch (Exception e)
            {
                ProcessorEventSource.Log.PartitionPumpCloseError(this.Host.HostName, this.PartitionContext.PartitionId, e.ToString());
                // If closing the processor has failed, the state of the processor is suspect.
                // Report the failure to the general error handler instead.
                this.Host.EventProcessorOptions.NotifyOfException(this.Host.HostName, this.PartitionContext.PartitionId, e, "Closing Event Processor");
            }

            if (reason != CloseReason.LeaseLost)
            {
                // Since this pump is dead, release the lease.
                try
                {
                    await this.Host.LeaseManager.ReleaseLeaseAsync(this.PartitionContext.Lease).ConfigureAwait(false);
                }
                catch (Exception e)
                {
                    // Log and ignore any failure since expired lease will be picked by another host.
                    this.Host.EventProcessorOptions.NotifyOfException(this.Host.HostName, this.PartitionContext.PartitionId, e, EventProcessorHostActionStrings.ReleasingLease);
                }
            }

            this.PumpStatus = PartitionPumpStatus.Closed;
            ProcessorEventSource.Log.PartitionPumpCloseStop(this.Host.HostName, this.PartitionContext.PartitionId);
        }
Пример #37
0
        // Websocket server events
        private void _appServer_SessionClosed(WebSocketSession session, CloseReason reason)
        {
            // Stop keepalive message timer
            KeepAliveDMYMsgTimer keepaliveMsgTimer = (KeepAliveDMYMsgTimer)session.Items["KeepAliveTimer"];

            keepaliveMsgTimer.Stop();

            IPAddress destinationAddress = session.RemoteEndPoint.Address;

            logger.Info("Session closed from : " + destinationAddress.ToString() + " Reason :" + reason.ToString());
        }
Пример #38
0
 public void OnDisconnect(WebSocketSession session, CloseReason reason)
 {
     string address = session.RemoteEndPoint.Address + ":" + session.RemoteEndPoint.Port;
     Player toRemove = GetPlayerByIP (address);
     if (toRemove != null) { //Did the player get as far as logging in?
         MainGame.entityHandler.RemoveEnt (toRemove);
         Logger.LogMsg (toRemove.name + " disconnected from the server. Reason " + reason.ToString ());
     }
 }
Пример #39
0
 public async Task CloseAsync(PartitionContext context, CloseReason reason)
 {
     Trace.TraceInformation(string.Format("EventProcessor Shuting Down.  Partition '{0}', Reason: '{1}'.", this.partitionContext.Lease.PartitionId, reason.ToString()));
     if (reason == CloseReason.Shutdown)
     {
         await context.CheckpointAsync();
     }
 }
Пример #40
0
 static void wsServer_SessionClosed(WebSocketSession session, CloseReason value)
 {
     Console.WriteLine("wsServer_SessionClosed. SessionCount=["
         + session.AppServer.SessionCount.ToString() + "] CloseReason=[" + value.ToString() + "]");
 }
        public Task CloseAsync(PartitionContext context, CloseReason reason)
        {
            Console.WriteLine(string.Format("EntityProcessor closing. Partition '{0}', Reason: '{1}'.", context.Lease.PartitionId, reason.ToString()));

            return(Task.FromResult <object>(null));
        }
        private static void MyServer_SessionClosed(MySession session, CloseReason closeReason)
        {
            var count = session.AppServer.SessionCount;

            LogHelper.Log.Info($"服务端 失去 来自客户端的连接,sessionID:" + session.SessionID + " closeReason:" + closeReason.ToString() + " count:" + count);
        }