views:

92

answers:

2

Hi, In Indy when we are sending some strings to the server , they change and will be shown in new format . for example i tried to send a binary file(File.exe) with "WriteLn" command in indy :

    Ms.LoadFromFile(FileAddress);

    Ms.Read(B, Chunk);

    for j := low(B) to high(B) do
    begin
      Part := Part + chr(B[j]);
    end;

and for sending strings :

FileClient.IOHandler.WriteLn(Part);

when client was sending strings to the server , i was monitoring the clinet with a sniffer . and finally i got this results :

MZ?.........yy..,.......@...................................,.....o..?.I!,.LI!This    program cannot be run in DOS mode....$..

As you see there are some characters that they are not in their true format any more and they changed to "?" character . but it should be noted that the sniffer automatically changed some string to "." , for example one of this points(".") is chr(0) or chr(5) maybe !!

but the sniffer couldn't change some characters to "." and we see them in "?" format . for example i open a binary file with notepad and you can see true format :

alt text Anyway , the question is : how can i send a binary file with "WriteLn" command in Indy 10 ?

+10  A: 

@Kermia, the WriteLn procedure is designed to send text data not binary, also adds a CRLF at the end of each mesagge sent.

You can use the WriteStream or Write procedure to send binary data.

if you insist in use the WriteLn procedure, you need to encode the binary data before sending using a Binary-to-text encoding like Base64, and after decode in the server side.

RRUZ
Agreed, especially since the data is coming from a TStream to begin with. Indy also has a WriteFile() method available as well, which opens a file and dumps its bytes as-is into the socket.
Remy Lebeau - TeamB
A: 

RRUZ , when yahoo! messenger was sending a file i sniff it and got this results :

alt text you can see that yahoo! messenger is sending a binary file(exe) in string format and there is no character in "?" format .

Kermia
Yahoo is NOT sending a binary file in text format. It is sending it in binary format. Look online at the actual Yahoo Messager protocol specs for details.
Remy Lebeau - TeamB
You probably should make this post as a section in your original question instead. Especially since this is not an answer but a reply to an answer.
TommyA