我尝试键入具有(客户端)和(多客户端服务器)的单个程序来发送和接收文件 传输完全成功,但程序(无响应)传输数据并在完成后正常返回
您可以通过以下链接下载项目: http ://www.mediafire.com/?81gs1zqbsgqldwb
请帮我解决程序传输数据时(无响应)的问题???
发送机制:
byte[] buffer = new byte[packetSize];
while (sum < length)
{
if (length - sum > packetSize)
{
count = fileStream.Read(buffer, 0, packetSize);
Send(socket_File, buffer);
}
else
{
buffer = new byte[length - sum];
count = fileStream.Read(buffer, 0, length - sum);
Send(socket_File, buffer);
}
sum = sum + count;
}
fileStream.Close();
接收机制:
string path = Save_File.FileName;
FileInfo fi = new FileInfo(path);
FileStream fs = fi.OpenWrite();
byte[] buffer = new byte[packetSize];
while (sum < File_Size)
{
if (File_Size - sum > packetSize)
{
count = Socket_File_Client.Receive(buffer, 0, packetSize, 0);
fs.Write(buffer, 0, count);
}
else
{
buffer = new byte[File_Size - sum];
count = Socket_File_Client.Receive(buffer, 0, File_Size - sum, 0);
fs.Write(buffer, 0, count);
}
sum = sum + count;
}
fs.Close();