111,078
社区成员




NetworkStream ns = tc.GetStream();
FileStream fs = new FileStream(@"F:\C#.NET网络编程.pdf", FileMode.OpenOrCreate, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
int count = 0;
double size = 0;
byte[] b = new byte[2048];
while ((count = br.Read(b, 0, 2048)) > 0)
{
try
{
ns.Write(b, 0, count);
size += count;
ns.Flush();
}
catch
{
Console.WriteLine("服务器已关闭!发送字节数为:" + size);
return;
}
}
Console.WriteLine("发送:" + string.Format("{0:F}", size / 1024) + " KB");
Console.WriteLine("文件传输完毕!");
//ns.Close();
//fs.Close();
//br.Close();
//tc.Close();