Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("TestRequestMultiResponseClient");

            var serverIp = "127.0.0.1";

            //var serverIp = "83.151.199.77";

            _clientConnector = new ClientConnector(new ClientConnectorSettings()
            {
                PacketsMap = new Dictionary <Tuple <int, int>, Type>()
                {
                    { new Tuple <int, int>(1, 1), typeof(GetListResponsePacket) },
                    { new Tuple <int, int>(1, 2), typeof(GetListResponsePacket) },
                },
                ServerAddressList = new List <Tuple <string, int> >()
                {
                    new Tuple <string, int>(serverIp, 1112)
                }
            });

            _clientConnector.OnPacket     += ClientConnector_OnPacket;
            _clientConnector.OnConnect    += ClientConnector_OnConnect;
            _clientConnector.OnDisconnect += ClientConnector_OnDisconnect;
            _clientConnector.OnException  += ClientConnector_OnException;
            _clientConnector.OnDebugLog   += ClientConnector_OnDebugLog;

            _clientConnector.Connect();

            while (true)
            {
                try
                {
                    Console.WriteLine("Enter Input (r-request, m-request multi response, x - test RequestMultiResponsesHandler)");
                    var inputLine = Console.ReadLine();

                    if (inputLine == "r")
                    {
                        Console.WriteLine("Perform Request (large single response)");
                        var resPacket = _clientConnector.SendRequest(1, 1, new GetListRequestPacket()) as GetListResponsePacket;
                        //Console.WriteLine($"response packet:{JsonConvert.SerializeObject(resPacket)}");
                        Console.WriteLine($"response packet count:{resPacket.Records.Count}");
                    }
                    else if (inputLine == "m")
                    {
                        Console.WriteLine("Perform Request - multi responses");

                        for (int i = 0; i < 10; i++)
                        {
                            _clientConnector.SendRequestMultiResponses(
                                1,
                                2,
                                new GetListRequestPacket(),
                                MultiResponseCallback);
                        }

                        //var resPacket = _clientConnector.SendRequest(1, 1, new GetListRequestPacket()) as GetListResponsePacket;
                        //Console.WriteLine($"response packet:{JsonConvert.SerializeObject(resPacket)}");
                        //Console.WriteLine($"response packet count:{resPacket.List.Count}");
                    }
                    else if (inputLine == "x")
                    {
                        Console.WriteLine("TestRequestMultiResponsesHandler");
                        var test = new TestRequestMultiResponsesHandler();
                        test.Run();
                    }
                    else
                    {
                        Console.WriteLine("input incorrect.");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception:" + ex.ToString());
                }
            }
        }