本帖最后由 李后量 于 2012-9-11 18:40 编辑  
 
正如视频里的那样,我做了一下聊天室小程序,只是我是从服务端发往客户端的,但运行的时候出现了发送文件成功但接收不了文件的现象。 
经过调试,发现从服务端发送没有问题,但在客户端接收的时候出现了这个问题:调试到弹出保存文件窗口 的时候程序就是不弹出那个SaveFileDialog 窗口~~~纠结了 
 
调试图片: 
 
 
当再次按下F11的时候客户端窗口就弹出来了,而不是理论上的保存文件窗口SaveFileDialog。 
 
下面是客户端接收端代码-  void RecMsg()
 
 -         {
 
 -             while (true)
 
 -             {
 
 -                 //定义一个用来接收数据的缓冲区(2M的字节数组)
 
 -                 byte[] byteRecMsg = new byte[1024 * 1024 * 2];
 
 -                 //将接收到的数据存入byteRecMsg中,并返回字节长度
 
 -                 int length= socketClient.Receive(byteRecMsg);
 
 -                 if (byteRecMsg[0] == 0)
 
 -                 {
 
 -                     //把从数组的第一个元素开始拿数据,一直到最后一个不为空的元素,然后进行转换
 
 -                     string strRecMsg = System.Text.Encoding.UTF8.GetString(byteRecMsg, 1, length-1);
 
 -                     ShowMsg("对方说:" + strRecMsg);
 
 -                 }
 
 -                 else if (byteRecMsg[0] == 1)
 
 -                 {
 
 -                     SaveFileDialog sfd = new SaveFileDialog();
 
 -                     sfd.ShowDialog();
 
 -                     if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
 
 -                     {
 
 -                         string fileSavePath = sfd.FileName;
 
 -                         using (FileStream fs = new FileStream(fileSavePath, FileMode.Create))
 
 -                         {
 
 -                             fs.Write(byteRecMsg, 1, length - 1);
 
 -                         }
 
 -                         ShowMsg("文件保存成功:" + fileSavePath);
 
 -                     }
 
 -                 }
 
 -             }
 
 -         }
 
  复制代码 下面是服务端发送文件的代码- private void btnSendFile_Click(object sender, EventArgs e)
 
 -         {
 
 -             using (FileStream fs = new FileStream(txtFilePath.Text,FileMode.Open))
 
 -             {
 
 -                 byte[] arrFile = new byte[1024 * 1024 * 2];
 
 -                 int length= fs.Read(arrFile, 0, arrFile.Length);
 
 -                 byte[] sendFile = new byte[length+1];
 
 -                 sendFile[0] = 1;
 
 -                 Buffer.BlockCopy(arrFile, 0, sendFile, 1, length);
 
 -                 string strClientKey = lbOnLine.Text;
 
 -                 dic[strClientKey].Send(sendFile);
 
 -                 ShowMsg("文件发送成功!");
 
 -             }
 
 -         }
 
  复制代码 大牛们帮看看这是肿么了~~~~ 
 
 
 |