public void doprocess(TcpClient client)
{
MemoryStream ms = new MemoryStream();
Stream clStream = client.GetStream();
byte[] buffer_1 = new byte[8192];
int count = clStream.Read(buffer_1, 0, buffer_1.Length);
while (count > 0)
{
ms.Write(buffer_1, 0, count);
//the below line doesn't gives response and code hangs here
count = clStream.Read(buffer_1, 0, buffer_1.Length);
}
}
有没有其他方法可以将一个流写入另一个流?我想两次使用这个Stream
,这就是为什么我需要将它写入MemoryStream
。如何将流写入内存流?
@purvang:啊,所以你是服务器,而不是客户...客户端要做什么?如果它没有关闭连接,你可以永远阅读... –
TcpClient client = tcplistener.AcceptTcpClient(); //它接受客户端请求 – purvang
客户端只是在浏览器中提供请求,我只是扫描请求是否正确,然后将其发送到原始服务器。所以我使用这个流来扫描请求,所以我需要使用两个流,一个用于显示,另一个用于扫描。我读了两次使用这个流,我应该把它写入内存流。请指导我!感谢你的回答!! – purvang