我正在尝试构建客户端应用程序:
ShellStream mainStream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024); //the library's class which represents the main stream of data between client and server
StreamReader reader = new StreamReader(mainStream);
StreamWriter writer = new StreamWriter(mainStream); //wrappers for the main stream
向服务器发送请求:
await writer.WriteAsync(command);
await writer.FlushAsync();
......并阅读回复:
async Task<string> GetResponse(CancellationToken cts)
StringBuilder sb = new StringBuilder();
char[] buffer = new char[128];
int i = 0;
while (!cts.IsCancellationRequested)//when timeout is tick then cancel operation
{
while ((i = await reader.ReadAsync(buffer, 0, buffer.Length)) != 0)
{
sb.Append(buffer, 0, i);
}
return sb.ToString();
问题是我无法从服务器读取响应,但StreamReader有一个内部char数组,charBuffer,它有响应。此外,GetResponse返回由StreamWriter编写的命令。这有什么不对?
编辑:当我更换`writer.WriteAsync(command);```writer.WriteLineAsync(command);`它开始工作了。但是当我发送特定命令(`geth --verbosity 0`)时,它不再发送。这种行为对我来说很奇怪。