ServerSocket 和 ClientSocket 之间,
可以传送和接收消息SendText和ReceiveText但如何传送和接收txt文件????????高分求救

解决方案 »

  1.   

    var
      strlist: Tstringlist;
    begin
      try 
        strlist := Tstringlist.Create;
        strlist.LoadFromFile(C:\test.txt);
        for i := 0 to strlist.Count - 1 do
        begin
         socket.SendText(strlist.strings[i] + CRLF);
        end;
      finally
       strlist.free;
      end;
    end;收要使用ReceiveBufprocedure TTLWallySmtp.RecvText;
    var
      r, i: Integer;
      s: string;
      buf: array[0..1023] of Char;
      ReplyCode, ReplyStr: string;
    begin
      ReplyCode := '';
      ReplyStr := '';
      i := 0;
      Repeat
        Application.ProcessMessages;
        r := Socket.ReceiveBuf(buf, SizeOf(buf));
        s := copy( buf, 1, r);
        ReplyCode := trim( copy( s, 1, 4));
        ReplyStr := trim( copy( s, 5, pos( CRLF, s) -5));
        i := i+1;
      until ((ReplyCode <> '') or (i>10));
        if ReplyCode <> '' then
        begin
             if (ReplyCode[1] <> '2') and (ReplyCode[1] <> '3') then
                raise Exception.Create(ReplyStr)
        end else
            raise Exception.Create('No Reply');
    end;