Пример #1
0
        static void Main(string[] args)
        {
            string[] info = get_IP_Port();
            //string[] info = new string[2];
            //info[0] = "127.0.0.1";
            //info[1] = "10000";

            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress  IP  = IPAddress.Parse(info[0]);
            IPEndPoint IEP = new IPEndPoint(IP, int.Parse(info[1]));

            socket.Bind(IEP);
            socket.Listen(maxConnect);
            Console.WriteLine(string.Format("服务器启动成功_{0}:{1}", info[0], info[1]));
            socket.BeginAccept(Callback_Accpet, socket);
            AccountManagement.getInstance();
            RoomManagement.getInstance();

            Thread heartBeat = new Thread(checkClient);

            heartBeat.Start();
            while (true)
            {
                Console.Read();
            }
        }
Пример #2
0
 public static AccountManagement getInstance()
 {
     if (instance == null)
     {
         instance = new AccountManagement();
     }
     return(instance);
 }
Пример #3
0
        /// <summary>
        /// 解析客户端数据
        /// </summary>
        /// <param name="s_data"></param>
        static void ParseClientData(Client CT, string msg)
        {
            string data = msg;
            string type;

            try
            {
                type = data.Substring(0, 2);
            }
            catch
            {
                type = "";
            }
            string result = "";

            switch (type)
            {
            //注册
            case "RG":
                result = AccountManagement.getInstance().Register(data);
                CT.Send(result);
                break;

            //登录
            case "LG":
                result = AccountManagement.getInstance().Login(data);
                if (result.Split(' ')[1].CompareTo("S") == 0)
                {
                    CT.ID      = result.Split(' ')[2];
                    CT.isLogin = true;
                }
                CT.Send(result);
                break;

            //创建房间
            case "CR":
                RoomManagement.getInstance().Parse(CT, data);
                break;

            //进入房间
            case "ER":
                RoomManagement.getInstance().Parse(CT, data);
                break;

            //心跳
            case "HB":
                CT.updateTick(ServerFunction.getTimeStamp());
                break;

            case "":
                CT.isLink = false;
                break;

            default:
                break;
            }
        }