Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void CannotConnectedServer(object sender, NetEventArgs e)
        {
            string info = "连接不到远程服务器!";

            WriteLog(info);
            //throw (new ApplicationException(info));
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void ConnectedServer(object sender, NetEventArgs e)
        {
            string info = string.Format("客户端: {0} 连接到了服务器: {1}.", e.Client.ID,
                                        e.Client.ClientSocket.RemoteEndPoint.ToString());

            WriteLog(info);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void ServerFull(object sender, NetEventArgs e)
        {
            string info = string.Format("服务器连接数已满.客户端: {0} 连接请求被拒绝.",
                                        e.Client.ClientSocket.RemoteEndPoint.ToString());

            //服务器满了,必须关闭新来的客户端连接
            e.Client.Close();
            Neusoft.FrameWork.Server.Pooling.CloseDB(e.Client.ID);
            WriteLog(info);
        }
Exemplo n.º 4
0
        public virtual void RecvdServerData(object sender, NetEventArgs e)
        {
            //liuke add 20091224 start
            string info = e.Client.Datagram.Trim('#');

            if (!string.IsNullOrEmpty(info))
            {
                lastRevMsg = info;
            }
            //liuke add 20091224 end
        }
Exemplo n.º 5
0
        protected virtual void KillMethod(NetEventArgs e, string killId)
        {
            Session client = (Session)ClientTable[killId];

            if (client != null)
            {
                CloseSession(client);
                tcpSvr.Send(e.Client, "Client is killed!##");
            }
            else
            {
                tcpSvr.Send(e.Client, "Client is not exist!##");
            }
        }
Exemplo n.º 6
0
        protected virtual void ListMethod(NetEventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            foreach (Session client in ClientTable.Values)
            {
                if (client != null)
                {
                    sb.Append(string.Format("Client:{0} connected server. SessionId is:{1}.",
                                            client.ClientSocket.RemoteEndPoint.ToString(),
                                            client.ID)).Append(Environment.NewLine);
                }
            }
            tcpSvr.Send(e.Client, string.Format("{0}##", sb.ToString().TrimEnd(Environment.NewLine.ToCharArray())));
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void DisConnectedServer(object sender, NetEventArgs e)
        {
            string info;

            if (e.Client.TypeOfExit == Session.ExitType.ExceptionExit)
            {
                //socket异常关闭表示客户端是正常点击关闭按钮退出的
                info = string.Format("客户端:{0} 正常关闭了.", e.Client.ID);
            }
            else
            {
                //socket正常关闭表示客户端是被服务器强制关闭连接的
                info = string.Format("客户端:{0} 异常关闭了.", e.Client.ID);
            }

            WriteLog(info);
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void ClientClose(object sender, NetEventArgs e)
        {
            string info;

            if (e.Client.TypeOfExit == Neusoft.FrameWork.Server.Session.ExitType.ExceptionExit)
            {
                //socket异常关闭表示客户端是正常点击关闭按钮退出的
                info = string.Format("客户端:{0} 正常关闭了.", e.Client.ID);
            }
            else
            {
                //socket正常关闭表示客户端是被服务器强制关闭连接的
                info = string.Format("客户端:{0} 异常关闭了.", e.Client.ID);
            }
            Pooling.CloseDB(e.Client.ID);
            WriteLog(info);
        }
Exemplo n.º 9
0
 public virtual void CannotConnectedServer(object sender, NetEventArgs e)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
 public virtual void ConnectingServer(object sender, NetEventArgs e)
 {
     tcpCli.Send(String.Format("{0}##", applicationId));
 }
Exemplo n.º 11
0
        protected virtual void InnerMethod(NetEventArgs e)
        {
            //liuke add 20091224 start
            string info = e.Client.Datagram.TrimEnd(Environment.NewLine.ToCharArray());

            if (!string.IsNullOrEmpty(info))
            {
                string[] para = info.Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
                if (para.Length == 2)
                {
                    ServerVerb sv;
                    try
                    {
                        sv = (ServerVerb)Enum.Parse(typeof(ServerVerb), para[0].ToUpper());
                    }
                    catch
                    {
                        tcpSvr.Send(e.Client, "Error Command!##");
                        return;
                    }
                    switch (sv)
                    {
                    case ServerVerb.KILL:
                        KillMethod(e, para[1]);
                        break;
                    }
                }
                else if (para.Length == 1)
                {
                    ServerVerb sv;
                    try
                    {
                        sv = (ServerVerb)Enum.Parse(typeof(ServerVerb), para[0].ToUpper());
                    }
                    catch
                    {
                        tcpSvr.Send(e.Client, "Error Command!##");
                        return;
                    }
                    switch (sv)
                    {
                    case ServerVerb.STATE:
                        StateMethod(e);
                        break;

                    case ServerVerb.COUNT:
                        CountMethod(e);
                        break;

                    case ServerVerb.LIST:
                        ListMethod(e);
                        break;

                    case ServerVerb.CLEAR:
                        ClearMethod();
                        break;

                    case ServerVerb.STOP:
                        StopMethod();
                        break;
                    }
                }
                else
                {
                    tcpSvr.Send(e.Client, "Error Command!##");
                    return;
                }
            }
            //liuke add 20091224 end
        }
Exemplo n.º 12
0
 protected virtual void CountMethod(NetEventArgs e)
 {
     tcpSvr.Send(e.Client, string.Format("Current count of Client is {0}/{1}.##",
                                         ClientCount, ServerCapacity));
 }
Exemplo n.º 13
0
        protected virtual void StateMethod(NetEventArgs e)
        {
            string state = IsServerRun ? "Server is running!" : "Server is not running!";

            tcpSvr.Send(e.Client, string.Format("{0}##", state));
        }
Exemplo n.º 14
0
 public virtual void RecvClientData(object sender, NetEventArgs e)
 {
     InnerMethod(e);
 }
Exemplo n.º 15
0
 public virtual void ClientClose(object sender, NetEventArgs e)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
 public virtual void ServerFull(object sender, NetEventArgs e)
 {
     throw new NotImplementedException();
 }