Home > Back-end >  IdTcpServer how to send the hexadecimal number problem, baidu to find a lot of, all the test.
IdTcpServer how to send the hexadecimal number problem, baidu to find a lot of, all the test.

Time:11-02

DELPHI 10.2
IdTcpServer controls

I now need to create a docking and single chip microcomputer, the other party can accept hexadecimal data, I am now going to send the data to the hexadecimal format, such as:
C7 44 C7 34, 66, 44, 86 and then how to send each other?

I now use:
Try
I:=combobox1. Items. IndexOf (combobox1. Text);
ConnContext:=TIdContext (idtcpserver1. Contexts. The LockList. Items [I]);
Conncontext. Connection. IOHandler. Writeln (memo1. Text);
The finally
IdTCPServer1. Contexts. UnlockList;
end;

Microcontroller to receive my data, but the other received is a string, he will put the data into hexadecimal, so can't return me to want to results,

Does the great god?

CodePudding user response:

What you send is a string, you want to write the string of hexadecimal corresponds to also can,
Or writeln to write, direct write TBytes
Exam:
Var
Buf: TBytes;
The begin
SetLength (buf, 7);
Buf [0] :=$C7.
Buf [1] :=$44.
Buf [2] :=$C7.
.
Conncontext. Connection. The IOHandler. Write (buf);
end;

CodePudding user response:

reference 1st floor day return reply:
what you send is string, do you want to write the string of hexadecimal corresponds to also can,
Or writeln to write, direct write TBytes
Exam:
Var
Buf: TBytes;
The begin
SetLength (buf, 7);
Buf [0] :=$C7.
Buf [1] :=$44.
Buf [2] :=$C7.
.
Conncontext. Connection. The IOHandler. Write (buf);
end;
this is a positive solution,

CodePudding user response:

reference 1st floor day return reply:
what you send is string, do you want to write the string of hexadecimal corresponds to also can,
Or writeln to write, direct write TBytes
Exam:
Var
Buf: TBytes;
The begin
SetLength (buf, 7);
Buf [0] :=$C7.
Buf [1] :=$44.
Buf [2] :=$C7.
.
Conncontext. Connection. The IOHandler. Write (buf);
end;



Thanks for support!!!!!!

Now I was taken out of a file inside the hexadecimal data is huge,

reference 1st floor day return reply:
what you send is string, do you want to write the string of hexadecimal corresponds to also can,
Or writeln to write, direct write TBytes
Exam:
Var
Buf: TBytes;
The begin
SetLength (buf, 7);
Buf [0] :=$C7.
Buf [1] :=$44.
Buf [2] :=$C7.
.
Conncontext. Connection. The IOHandler. Write (buf);
end;



reference 1st floor day return reply:
what you send is string, do you want to write the string of hexadecimal corresponds to also can,
Or writeln to write, direct write TBytes
Exam:
Var
Buf: TBytes;
The begin
SetLength (buf, 7);
Buf [0] :=$C7.
Buf [1] :=$44.
Buf [2] :=$C7.
.
Conncontext. Connection. The IOHandler. Write (buf);
end;


18 years of the great god ah, nice to meet you, thank you for support,

I'm still stuck here, in fact I was around in,

I here by idTcpServer is going to send a picture to the client, the client has a display screen, accept normal send will show me the picture), the client can only accept the hex, I wanted to put images into hexadecimal before you write, now want to is more get more complex,

Can you give a piece of code? I through the Internet to find information, compiled a below and send a bit slower, can travel a line above the screen color, no pictures, I want
Procedure TForm1. Button3Click (Sender: TObject);
Var
Mem: TMemoryStream;
BMP: tBitmap;
Buf: an array of byte;
I, j, bsize: integer;
ConnContext: Tidcontext;
The begin
Mem:=TMemoryStream. Create;
BMP:=Tbitmap. Create;

BMP. LoadFromFile (' d: \ soft \ ABC BMP);
BMP. SaveToStream (mem);
BSize:=mem. Size;

SetLength (buf, bSize);
Mem. Position:=0;
Mem. Readbuffer (buf [0], bSize);


I:=combobox1. Items. IndexOf (combobox1. Text);
ConnContext:=TIdContext (idtcpserver1. Contexts. The LockList. Items [I]);

For j:=0 to Bsize do
ConnContext. Connection. IOHandler. Write (buf [j])


end;



CodePudding user response:

The Write method can one-time Write, don't need a byte at a time, using the Write (buf) try,
In addition, I saw there is WriteFile this method, also can try,

CodePudding user response:

Since is the hexadecimal data, that should be sent the string 'C744C744863466'

CodePudding user response:

Images are hexadecimal data, to put it bluntly, the inside of the computer data is hexadecimal, are also 2 base, is a one Byte bytes,

For Indy, it can send TBytes, so your question is, how to put the image file is converted into a TBytes, I forgot to Indy whether can send TStream directly, if you can, your image file, with TFileStream loading and then directly sent directly is ok,

If Indy cannot send TStream, so, you want to do is make one TBytes, has moved in the file content, method is to make a TFileStream to load the file, and then set the size and the size of the TFileStream TBytes, and TFileStream ReadBuffer can move its content TBytes,

Indy as is with TIdBytes,,

In addition, the single chip microcomputer to write data, to take care of it, the speed of the computer carefully this way too fast, microcontroller busy don't come out of the question,

CodePudding user response:

This I have done, but I was to receive from each other by WEBSERVICE JPG images, I pasted the code, I hope it can help you,
This is a server-side code, because the incoming XML is a string, so I receive the string translates into jpeg and then save to the database,




Below is the client, how to convert a jpeg to a standard XML





  • Related