/// <summary> /// /// </summary> /// <param name="menu"></param> /// <param name="entry"></param> /// <param name="option"></param> /// <param name="o"></param> /// <returns></returns> static bool TestListener(MenuList menu, CMenu entry, char option, object o) { TestListenerType type = (TestListenerType)o; type.FileToUse = Input("File to use", LISTENER_TEST_FILE, out bool isdef); if (string.IsNullOrEmpty(type.FileToUse)) { Console.WriteLine("Invalid test file"); return(true); } type.IP = Input("Listener IP", CStream.Localhost(), out isdef); if (string.IsNullOrEmpty(type.IP)) { Console.WriteLine("Invalid IP"); return(true); } string sport = Input("Listener port to reach", type.Port.ToString(), out isdef); if (string.IsNullOrEmpty(sport)) { return(true); } try { type.Port = uint.Parse(sport); } catch (Exception) { Console.WriteLine("Invalid port number"); return(true); } //var json = new CJson<CListenerRequest>(fileToUse); //var request = json.ReadSettings(out bool except); //if (null != request) //{ // var sreply = CStream.ConnectSendReceive(new CStreamClientSettings() { IP = ip, Port = port }, CJson<CListenerRequest>.Serialize(request), out int size, out bool error); // if (!string.IsNullOrEmpty(sreply)) // { // CLogger.Add(sreply); // var reply = CJson<CListenerReply>.Deserialize(sreply, out except); // CLogger.Add(reply.ToString()); // } // else // CLogger.Add("No reply has been received"); //} var json = new CJson <CListenerRequest>(type.FileToUse); var request = json.ReadSettings(out bool except); if (null != request) { CStreamClientIO streamIO = CStream.Connect(new CStreamClientSettings() { IP = type.IP, Port = type.Port }); if (null != streamIO) { if (CStream.Send(streamIO, CJson <CListenerRequest> .Serialize(request))) { string sreply; while (!string.IsNullOrEmpty(sreply = CStream.Receive(streamIO, out int announcedSize, out bool error))) { var reply = CJson <CListenerReply> .Deserialize(sreply, out except); CLogger.Add($"{reply.ToString()} (received message)"); if (!reply.Notification) { break; } } } } } return(true); }