private void InitClientConnector() { _clientConnector = new ClientConnector(new ClientConnectorSettings() { PacketsMap = new Dictionary <Tuple <int, int>, Type>(_packetsMap), ServerAddressList = new List <Tuple <string, int> >() { new Tuple <string, int>(Program.AppSettingsClient.ServerAddress, 1112) } }); _clientConnector.OnPacket += ClientConnector_OnPacket; _clientConnector.OnConnect += ClientConnector_OnConnect; _clientConnector.OnDisconnect += ClientConnector_OnDisconnect; _clientConnector.OnException += ClientConnector_OnException; _clientConnector.OnDebugLog += ClientConnector_OnDebugLog; _clientConnector.Connect(); object loginResponse = null; try { loginResponse = _clientConnector.SendRequest(new LoginRequestPacket { Username = "******" }); } catch (Exception ex) { Console.WriteLine("Exception on first packet:" + ex.ToString()); } Console.WriteLine($"Response loginResponse:{JsonConvert.SerializeObject(loginResponse)}"); }
static void Main(string[] args) { Console.WriteLine("TestSimpleEchoClient"); _clientConnector = new ClientConnector(new ClientConnectorSettings() { PacketsMap = new Dictionary <Tuple <int, int>, Type>() { { new Tuple <int, int>(1, 1), typeof(string) }, }, ServerAddressList = new List <Tuple <string, int> >() { new Tuple <string, int>("127.0.0.1", 1112) } }); _clientConnector.OnPacket += ClientConnector_OnPacket; _clientConnector.OnConnect += ClientConnector_OnConnect; _clientConnector.OnDisconnect += ClientConnector_OnDisconnect; _clientConnector.OnException += ClientConnector_OnException; _clientConnector.OnDebugLog += ClientConnector_OnDebugLog; _clientConnector.Connect(); try { _clientConnector.Send(1, 1, "start"); } catch (Exception ex) { Console.WriteLine("Exception on first packet:" + ex.ToString()); } while (true) { try { Console.WriteLine("Enter Input"); var inputLine = Console.ReadLine(); if (inputLine == "exp") { _clientConnector.SendRequest(1, 1, inputLine); } else { _clientConnector.Send(1, 1, inputLine); } } catch (Exception ex) { Console.WriteLine("Exception:" + ex.ToString()); } } }
private void ReportRequestTimer_Elapsed(object sender, ElapsedEventArgs e) { if (Program.AppSettingsClient.ReportRequestSecondsInterval == 0) { return; } try { if (_rnd.Next(Program.AppSettingsClient.ReportRequestSecondsInterval) == 0) { var res = _clientConnector.SendRequest(new ReportRequestPacket() { ReportName = "X" }) as ReportResponsePacket; Console.WriteLine(res.Records.Count); } } catch (Exception ex) { } }
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()); } } }