0
因此,我無法讀取通過Tcp流發送的字符串。我正在使用此代碼發送。從TcpClient讀取字符串
byte[] bytes = ASCIIEncoding.ASCII.GetBytes("connect");
NetworkStream stream = client.GetStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(bytes);
writer.Close();
而這種代碼改爲:
public void getConnectionString()
{
NetworkStream ns = client.GetStream();
byte[] bytes = new byte[client.ReceiveBufferSize];
ns.Read(bytes, 0, bytes.Length);
string info = Encoding.ASCII.GetString(bytes);
MessageBox.Show(info);
}
但是,這一切正在恢復的系統:字節[]
難道不應該返回字符串?我究竟做錯了什麼?