public async Task RequestBytes_Selector_SendsSelectorValue() { var connection = new Async(connectionClient); var stream = new MemoryStream(); connectionClient.Connected.Returns(true); connectionClient.GetStream().Returns <Stream>(stream); await connection.OpenAsync("", 0); await connection.RequestBytesAsync("info"); connectionClient.Received(1).GetStream(); byte[] data = new byte[stream.Length]; stream.Position = 0; stream.Read(data, 0, data.Length); var result = new string(Encoding.ASCII.GetChars(data)); Assert.AreEqual("info", result); }
public Span <byte> RequestBytes(string path) { if (open == false) { throw new Exception(); } using var stream = client.GetStream(); // Send the request selector var pathBytes = Encoding.ASCII.GetBytes(path); stream.Write(pathBytes, 0, pathBytes.Length); stream.Flush(); int chunk = 1024; var buffer = new List <byte[]>(); int read; var terminator = new byte[3] { (int)'\r', (int)'\n', (int)'.' }; do { var data = new byte[chunk]; try { read = stream.Read(data, 0, chunk); } catch //Server closed stream etc. { break; } if (read > 0) { buffer.Add(data[0..read]);