コード例 #1
0
ファイル: Program.cs プロジェクト: hothoty/Zero
        static void Main(string[] args)
        {
            // udp 송신 모드
            bool mode_send_udp = false;

            CClient Client = new CClient();

            Client.m_Core.Connect(
                "127.0.0.1",
                20000,
                0,          // protocol version
                77,         // udp recve port : if 0 = disable
                false,      // mobile option (모바일 클라이언트인 경우 true사용 권장)
                false       // enable auto connection recovery mode
                );

            Console.Write("> ");

            var ret = ReadLineAsync();
            bool run_program = true;
            while (run_program)
            {
                if (ret.IsCompleted)
                {
                    switch (ret.Result)
                    {
                        case "/q":
                            Client.m_Core.Leave();
                            break;

                        case "/exit":
                            run_program = false;
                            break;

                        case "/h":
                            Console.WriteLine("/Cmd:  h(Help) q(Quit) u(udp toggle) exit(ProgramExit)");
                            break;

                        case "/u":
                            // udp 모드 토글
                            mode_send_udp = !mode_send_udp;
                            Console.WriteLine("Current mode udp is {0}", mode_send_udp);
                            break;

                        default:
                            // 패킷 보내기
                            if (mode_send_udp)
                                Client.proxy.request_Udp(ZNet.RemoteID.Remote_Server, ZNet.CPackOption.Udp, ret.Result);
                            else
                                Client.proxy.request_Udp(ZNet.RemoteID.Remote_Server, ZNet.CPackOption.Basic, ret.Result);

                            // 패킷 받을때 처리
                            Client.stub.reponse_Udp = (ZNet.RemoteID remote, ZNet.CPackOption pkOption, string msg) =>
                            {
                                if (pkOption.IsUdp())
                                    Console.WriteLine(string.Format("recv(udp) : {0}", msg));
                                else
                                    Console.WriteLine(string.Format("recv(tcp) : {0}", msg));
                                return true;
                            };
                            break;
                    }

                    if (run_program)
                        ret = ReadLineAsync();
                }

                Client.m_Core.NetLoop();
                System.Threading.Thread.Sleep(1);
            }

            Client.m_Core.Destroy();
            System.Threading.Thread.Sleep(1000 * 2);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: wonderfl/Zero
        static void Main(string[] args)
        {
            // udp 송신 모드
            bool mode_send_udp = false;

            CClient Client = new CClient();

            Client.m_Core.Connect(
                "127.0.0.1",
                20000,
                0,          // protocol version
                77,         // udp recve port : if 0 = disable
                false,      // mobile option (모바일 클라이언트인 경우 true사용 권장)
                false       // enable auto connection recovery mode
                );

            Console.Write("> ");

            var  ret         = ReadLineAsync();
            bool run_program = true;

            while (run_program)
            {
                if (ret.IsCompleted)
                {
                    switch (ret.Result)
                    {
                    case "/q":
                        Client.m_Core.Leave();
                        break;

                    case "/exit":
                        run_program = false;
                        break;

                    case "/h":
                        Console.WriteLine("/Cmd:  h(Help) q(Quit) u(udp toggle) exit(ProgramExit)");
                        break;

                    case "/u":
                        // udp 모드 토글
                        mode_send_udp = !mode_send_udp;
                        Console.WriteLine("Current mode udp is {0}", mode_send_udp);
                        break;

                    default:
                        // 패킷 보내기
                        if (mode_send_udp)
                        {
                            Client.proxy.request_Udp(ZNet.RemoteID.Remote_Server, ZNet.CPackOption.Udp, ret.Result);
                        }
                        else
                        {
                            Client.proxy.request_Udp(ZNet.RemoteID.Remote_Server, ZNet.CPackOption.Basic, ret.Result);
                        }

                        // 패킷 받을때 처리
                        Client.stub.reponse_Udp = (ZNet.RemoteID remote, ZNet.CPackOption pkOption, string msg) =>
                        {
                            if (pkOption.IsUdp())
                            {
                                Console.WriteLine(string.Format("recv(udp) : {0}", msg));
                            }
                            else
                            {
                                Console.WriteLine(string.Format("recv(tcp) : {0}", msg));
                            }
                            return(true);
                        };
                        break;
                    }

                    if (run_program)
                    {
                        ret = ReadLineAsync();
                    }
                }

                Client.m_Core.NetLoop();
                System.Threading.Thread.Sleep(1);
            }

            Client.m_Core.Destroy();
            System.Threading.Thread.Sleep(1000 * 2);
        }