Exemple #1
0
        /// <summary>
        /// 断开成功通知函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SocketClosed(object sender, SocketAsyncEventArgs e)
        {
            SocketListener sl = sender as SocketListener;
            Socket         s  = (e.UserToken as AsyncUserToken).CurrentSocket;

            //将接收的缓冲删除
            lock (dictInPackets)
            {
                if (dictInPackets.ContainsKey(s))
                {
                    TCPInPacket tcpInPacket = dictInPackets[s];
                    tcpInPacketPool.Push(tcpInPacket); //缓冲回收
                    dictInPackets.Remove(s);
                }
            }

            //断开连接时,清除会话实例
            lock (gameServerClients)
            {
                GameServerClient client = null;
                if (gameServerClients.TryGetValue(s, out client))
                {
                    client.release();
                    gameServerClients.Remove(s);
                }
            }

            //通知主窗口显示连接数
            //RootWindow.Dispatcher.BeginInvoke((MethodInvoker)delegate
            //{
            RootWindow.TotalConnections = sl.ConnectedSocketsCount;
            //});
        }
Exemple #2
0
        private void SocketClosed(object sender, SocketAsyncEventArgs e)
        {
            SocketListener sl = sender as SocketListener;
            Socket         s  = (e.UserToken as AsyncUserToken).CurrentSocket;

            lock (this.dictInPackets)
            {
                if (this.dictInPackets.ContainsKey(s))
                {
                    TCPInPacket tcpInPacket = this.dictInPackets[s];
                    this.tcpInPacketPool.Push(tcpInPacket);
                    this.dictInPackets.Remove(s);
                }
            }
            lock (this.gameServerClients)
            {
                GameServerClient client = null;
                if (this.gameServerClients.TryGetValue(s, out client))
                {
                    client.release();
                    this.gameServerClients.Remove(s);
                }
            }
            this.RootWindow.TotalConnections = sl.ConnectedSocketsCount;
        }