【40分】求一个 tcpclient 和 TCPserver 传送文件的例子
我发送的都是 小于300K的jpg图像 能传送和接收就行越简单越好 例如 客户端 读取 c:\1.jpg 服务端收取后保存为 c:\2.jpg 就这个功能,希望高手不吝指教

解决方案 »

  1.   

    d7里面的demo就有个发送消息的例子
    再给你个原来已经解决过的发送文件的例子
    http://topic.csdn.net/t/20040402/11/2917158.html
      

  2.   

    function   DoSendFile(FileName:   string;   IP,   Port:   Integer):   Boolean;   
      var   
          Stream:   TFileStream;   
          TcpClient:   TTcpClient;   
          ReadCount,   LCount:   Integer;   
          Buffer:   array[0..1023]   of   Char;   
      label:   
        RET;   
      begin   
          //创建文件流   
          try   
              Stream   :=   TFileStream.Create(FileName,   fmOpenRead);   
          except   
              Result   :=   False;   
              goto   RET;   
          end;   
        
          //创建TCP连接   
          TcpClient   :=   TTcpClient.Create(Self);   
          try   
              TcpClient.RemoteHost   :=   IPToString(IP);   
              TcpClient.RemotePort   :=   Port;   
              TcpClent.Active   :=   False;   
          except   
              Result   :=   False;   
              goto   RET;   
          end;   
        
          //传送文件   
          LCount   :=   Stream.Size;   
          while   LCount   >   0   do   
          begin   
              //网络中断   
              if   not   TcpClient.Connected   then   Break;   
              ReadCount   :=   Min(1024,   LCount);   
              Stream.Read(Buffer,   ReadCount);   
              TcpClient.SendBuf(Buffer,   ReadCount);   
          end;   
        
        if   LCount   =   0   then   
            Result   :=   True   
        else   
          Result   :=   False;   
      RET:   
          Stream.Free;   
          TcpClient.Free   
      end;   这段代码的接收端怎么弄?
      

  3.   

    盒子上有现成的代码,你用upp用户搜索一下就可以。