开发者

Sending special strings with "WriteLn" in "Indy" (Delphi)

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 开发者_如何学JAVAwith 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 http://up.iranblog.com/Files/9f195012dbc2425b8773.png Anyway , the question is : how can i send a binary file with "WriteLn" command in Indy 10 ?


@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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜