public static void CheckReads() { NetworkStream nets = tcp.GetStream(); if (nets.DataAvailable) { byte[] rbuf = new byte[4096]; StringBuilder sb = new StringBuilder(); int read = 0; do { read = nets.Read(rbuf, 0, rbuf.Length); sb.AppendFormat("{0}", Encoding.UTF8.GetString(rbuf, 0, read)); } while(nets.DataAvailable); string data = sb.ToString(); EvaluationResult ev = EvaluationResultParser.Parse(data); Console.WriteLine(); Console.WriteLine(ev.ToString()); } }
public static void Main(string[] Arguments) { try { Console.Title = "Brew.js link - Windows client"; Log("Which is the Nintendo Switch's IP address? ", LogType.Information, false); string ipadd = Console.ReadLine(); tcp = new TcpClient(); Log("Connecting to Brew.js link homebrew with IP address " + ipadd + "...", LogType.Information); tcp.Connect(ipadd, BrewPort); Log("Connected to Brew.js link homebrew interpreter!", LogType.Information); while (true) { NetworkStream nets = tcp.GetStream(); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("> "); Console.ForegroundColor = ConsoleColor.White; string cmdlinetext = Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Gray; if (string.IsNullOrEmpty(cmdlinetext)) { continue; } byte[] cmdlinebytes = Encoding.ASCII.GetBytes(cmdlinetext); nets.Write(cmdlinebytes, 0, cmdlinebytes.Length); while (!nets.DataAvailable) { ; } byte[] rbuf = new byte[4096]; StringBuilder sb = new StringBuilder(); int read = 0; do { read = nets.Read(rbuf, 0, rbuf.Length); sb.AppendFormat("{0}", Encoding.UTF8.GetString(rbuf, 0, read)); } while(nets.DataAvailable); string data = sb.ToString(); EvaluationResult ev = EvaluationResultParser.Parse(data); Console.WriteLine(); Console.WriteLine(ev.ToString()); if (!ev.IsOK) { } else { Console.WriteLine(); Console.WriteLine(ev.ToString()); }; } } catch (Exception ex) { Console.Clear(); Log("An error happened (" + ex.GetType().ToString() + ")", LogType.Error); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(" - "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Press any key to exit."); Console.ReadKey(); } }