日期:2014-05-17 浏览次数:21084 次
private void SendFileStream(Socket socketStream, FileStream fs, byte[] byPack, string strFileName) { byte[] byHead = new byte[128]; byHead[0] = byPack[0]; byHead[1] = byPack[1]; byte[] byFileName = encodingGB.GetBytes(strFileName); byHead[2] = Convert.ToByte(byFileName.Length); byFileName.CopyTo(byHead, 3); if (socketStream != null) { SocketSendMessage(socketStream, byHead); } else { MessageBox.Show("socket"); return; } //socketStream.Send(byHead); byte[] byBody = new byte[PACKET_SIZE]; int nPackCount = Convert.ToInt32(byPack[0]) * Convert.ToInt32(byPack[1]); int nCurrentPack = 0; while (true) { if (socketStream != null) { SocketReceiveMessage(socketStream); } if (Convert.ToChar(byRec[0]) == 'E') { fs.Dispose(); fs.Close(); break; } else if (Convert.ToChar(byRec[0]) == 'S') { nCurrentPack = Convert.ToInt32(byRec[1]) * 256 + Convert.ToInt32(byRec[2]); fs.Seek((nCurrentPack - 1) * PACKET_SIZE, SeekOrigin.Begin); byBody = new byte[PACKET_SIZE]; if ((nCurrentPack == nPackCount) && (nLastPackSize != 0)) { fs.Read(byBody, 0, nLastPackSize); } else { fs.Read(byBody, 0, PACKET_SIZE); } if (socketStream != null) { SocketSendMessage(socketStream, byBody); } else { MessageBox.Show("socket"); return; } } } }
------解决方案--------------------
public struct FilePack
{
/// <summary>
/// 数据包大小
/// </summary>
public ushort PackSize;
/// <summary>
/// 文件GUID
/// </summary>
public byte[] FileGuid; //16
///// <summary>
///// 包数据SHA1验证 ...
///// </summary>
//public byte[] PackSHA1;
/// <summary>
/// 包总数量
/// </summary>
public ushort PackCount;
/// <summary>
/// 包号
/// </summary>
public ushort PackIndex;
/// <summary>
/// 包数据
/// </summary>
public byte[] PackData;
}
这样发啊...
------解决方案--------------------