日期:2014-05-17 浏览次数:20766 次
public void SendFile(Socket s, string filename)
{
FileInfo fi = new FileInfo(filename);
byte[] len = BitConverter.GetBytes(fi.Length);
//首先把文件长度发送过去
s.BeginSendFile(filename,len,null,TransmitFileOptions.UseDefaultWorkerThread,new AsyncCallback(SendFileCallback),null);
}
public void SendFileCallback(IAsyncResult iar)
{
clientSocket.EndSendFile(iar);
lstServer.Items.Add(DateTime.Now + "The pic\"" + path + "\" has been SENT....");
}
public void BeginReceive()//调用此函数 接收文件的开始工作
{
byte[] buffer = new byte[8];
//由于long占8位字节,所以先获取前8位字节数据
IAsyncResult iar = client.BeginReceive(
buffer,
0,
buffer.Length,
SocketFlags.None,
null,