日期:2014-05-17 浏览次数:20834 次
发送方法
public void SendFile(IPEndPoint ipRemote, string sFilePath)
{
int iReadLen;
byte[] fileData;
NetworkStream nStream;
//try
//{
tClient = new TcpClient(ipRemote.Address.ToString(), ipRemote.Port);
tClient.SendBufferSize = Settings.iMaxBufferSize;
FileStream fStream = new FileStream(sFilePath, FileMode.Open);
nStream = tClient.GetStream();
do
{
fileData = new byte[Settings.iMaxBufferSize];
iReadLen = fStream.Read(fileData, 0, fileData.Length);
SendNow(fileData,iReadLen);
//nStream.Write(fileData, 0, iReadLen);
if (SendPartCompleted != null)
SendPartCompleted(iReadLen);
} while (iReadLen > 0);
nStream.Flush();
fStream.Close();
nStream.Close();
if (SendAllCompleted != null)
SendAllCompleted();
//}
//catch (Exception e)
//{
&nb