Example #1
0
        public static AsynchronousClient Create(EServerType _type, SIpPort sip)
        {
            var client = new AsynchronousClient(_type);

            client.SetIpPort(sip.Ip, sip.Port);
            return(client);
        }
        static void Main()
        {
            App_Update.Init();
            App_Event.Init();



            App_ClientSocket.InitSocket(EServerType.Type_Login, SIpPort.Create(ip_login, port_login));
            //  App_ClientSocket.InitSocket(EServerType.Type_Game, SIpPort.Create(ip_game, port_game));


            AsynchronousClient clientSocket = App_ClientSocket.ClientSockets[EServerType.Type_Login];

            clientSocket.conFinishedCallback = (bool succeed) =>
            {
                if (succeed)
                {
                    Log("Type_Login" + "===Connected Succeed");
                    PacketSend pk = PacketSend.Create(EEvents.Event_LoginHeart);
                    pk.Write((byte)1);
                    pk.Write("meng dong..你好");

                    App_ClientSocket.Send(pk, EServerType.Type_Login);

                    pk = PacketSend.Create(EEvents.Event_ServerTime);
                    App_ClientSocket.Send(pk, EServerType.Type_Login);
                }
                else
                {
                    Log("Type_Login" + "===Connected Failed!!!");
                }
            };
            clientSocket.HandleConnect();


            //if (!App_ClientSocket.ClientSockets.ContainsKey(EServerType.Type_Game))
            //{
            //    Log("Error!!!===!App_ClientSocket.ClientSockets.ContainsKey(EServerType.Type_Game)");
            //    return;
            //}

            //clientSocket = App_ClientSocket.ClientSockets[EServerType.Type_Game];
            //clientSocket.conFinishedCallback = (bool succeed) =>
            //{
            //    if (succeed)
            //    {
            //        Log("Type_Game" + "===Connected Succeed");
            //        PacketSend pk = PacketSend.Create(EEvents.Event_GameHeart);
            //        App_ClientSocket.Send(pk, EServerType.Type_Game);
            //    }
            //    else
            //    {
            //        Log("Type_Game" + "===Connected Failed!!!");
            //    }
            //};
            //clientSocket.HandleConnect();

            Start();
        }
        /// <summary>
        /// 初始化指定类型的socket
        /// </summary>
        /// <param name="type">EServerType</param>
        /// <param name="ipp">SIpPort</param>
        public static void InitSocket(EServerType type, SIpPort ipp)
        {
            dicIPs[type] = ipp;

            dicClients[type] = AsynchronousClient.Create(type, ipp);
        }