程序在根据以下代码下载文件时自行锁定:可能是什么问题?
if (bufferInfo.Contains("fileExists"))
{
FileStream downloadFileStream = new FileStream(folderName + "\\" + requestFileName.Text, FileMode.Create);
activityLog.AppendText("File is found, it will be downloaded !");
byte[] myReadBufferExists = new byte[8196];
do
{
bytesRead = clientSocket.Receive(myReadBufferExists);
downloadFileStream.Write(myReadBufferExists,0,bytesRead);
} while (bytesRead != 0);
downloadFileStream.Close();
clientSocket.Close();
bufferInfo.Replace("fileExists","");
activityLog.AppendText("File has been received now writing to the disk...");
}
答案 0 :(得分:2)
它会锁定clientSocket.Receive(myReadBufferExists)
来电。这是因为默认情况下,Receive会尝试填充您传递的缓冲区。如果你无休止地调用Receive,它将在没有更多数据的情况下最终阻止。
情侣选择:
Connection: close
。当他们关闭连接时,接收将弹出(通过异常 - 由同伴关闭连接),你就会知道你已经完成了。