我想清空套接字的读取缓冲区,所以我编写了以下代码......
byte[] tempBuffer = new byte[1024];
int readCount = 0;
while ((readCount = tcpSocket.GetStream().Read(tempBuffer, 0, tempBuffer.Length)) != 0)
{
// do with tempBuffer
}
但是 Read() 方法被阻止了,所以我添加了tcpSocket.ReceiveTimeout = 1; . 它就像以前一样工作。
据我所知,这通常用于 C++。我怎么解决这个问题?