日期:2014-05-17 浏览次数:20746 次
//这里递归每一个文件并传给客户端
foreach (FileInfo file in files)
{
UpLoadBatchOneFile(file, clientSocket);
Thread.Sleep(1000);
}
//单个文件上传
private void UpLoadBatchOneFile(FileInfo file, Socket client)
{
try
{
//打开文件流
FileStream fileStream = file.OpenRead();
//包的数量:这个PacketCount大小不包括最后一个小于PacketSize的包。
int PacketCount = (int)(fileStream.Length / ((long)packetSize));
//最后一个包的大小
int LastDataPacket = (int)(fileStream.Length - ((long)(packetSize * PacketCount)));
//获得客户端节点对象
IPEndPoint clientep = (IPEndPoint)client.RemoteEndPoint;
//发送[根目录名]到客户端
TransferFiles.SendVarData(client, System.Text.Encoding.Unicode.GetBytes(rootFolder));
//发送[文件名]到客户端
TransferFiles.SendVarData(client, System.Text.Encoding.Unicode.GetBytes(file.FullName.Replace(replaceString,"")));
//发送[包的大小]到客户端
TransferFiles.SendVarData(client, System.Text.Encoding.Unicode.GetBytes(packetSize.ToString()));
//发送[包的总数量]到客户端
TransferFiles.SendVarData(client, System.Text.Encoding.Unicode.GetBytes(PacketCount.ToString()));
//发送[最后一个包的大小]到客户端
&n