Urgent question: the idtcpserver package is misplaced.

Source: Internet
Author: User
Urgent question: how to troubleshoot idtcpserver package misplacement? Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiNetwork/html/delphi_20061204132847206.html
I want to use idtcpserver as a main site software to receive packets sent by a remote terminal through the GPRS function.
In idtcpserverexecute, the packet received by reading athread. Connection. readln is found to be totally misplaced, which is equivalent to a packet consisting of half of the previous packet and half of the next packet. Each packet is divided into two halves and then half of the upstream and downstream packets are combined to form a new packet.
Is it because readln uses a carriage return to determine the end of the packet, so once 0d 0a appears in the packet, the packet will think it has been completed? It may be more suitable for transmission of ASCII messages than for transmission of such packets.
How should we solve this problem? Or do I have to use other methods instead of readln? Cainiao is new to Delphi. I am eager to advise you. Thank you!

Readln does determine whether there is 0d 0a, and a row ends.
If your data contains 0d 0a, it is recommended to use sendbuf to send (packed)

thank you for your answers.
now the key issue is acceptance. If you send the message, you are advised to use sendbuffer, will you accept readbuffer? Do you know any related examples of Programs ? I have never used this before. I don't know its mechanism and usage. I used readbuffer to find that each long frame is divided into several short frames. Why?
I am confused when I use this task for the first time. I hope you will give me some advice. Thank you! ^ _ ^

Generally, the packet body is sent with a packet header, which is very simple. Generally, it is the size of the packet to be read. After the packet header is taken, take the package body according to the size of the packet header.
For example:
Theader = record (
Total_length: uint; // total message length (including the message header and Message Body)
Command_id: uint; // command ID
Sequence_id: uint; // the serial number of the message, which is accumulated sequentially. The step size is 1 and is used cyclically.
End;
)
Readbuffer (header, sizeof (theader) // retrieves the header,
Readbuffer (body, header. Total_Length-SizeOf (theader); // obtain the packet body according to the packet header

Thank you for your answers!
Does the header theader have its own definition? Is it necessary to define such a record according to the protocol of your own packets as you mentioned in theader, read the packet header first each time, find the length from the packet header, and then read it into the buffer zone I want?
My current program is:
Procedure ttcp_client.idtcpserverexecute (athread: tidpeerthread );
VaR
Connected: Boolean;
Ain: array [0 .. 2047] of byte;
I, ilen: integer;
Begin
Connected: = true;
For I: = 0 to 2047 do
Ain [I]: = 0;
Athread. Connection. readfromstack;
Ilen: = athread. Connection. inputbuffer. size;

If ilen <> 0 then
Begin
Athread. Connection. readbuffer (AIN, ilen );
End;
End;
Is it true to read the data according to athread. Connection. inputbuffer. Size?
In addition, do I need to perform other actions before the idtcpserverexecute statement is in readbuffer? I checked the readbuffer in help and he said that the readfromstack should be used to ensure that at least the defined size data has been found in the buufer, but I used the program written above to easily die there, if an error occurs, is my usage incorrect?

I'm sorry for so many questions.

Your reading method is not very good, it is easy to show the package
Theader is customized and contains the size of the package,
Then read the specified size, so that no more or less read will be performed.

In fact, you have defined the data structure of your transfer package (usually defined as record), and then you can directly transfer the records. Here is an instance for you.

Note: when defining the record field type as string, the design length is set to a maximum length of 255. If not, define array string.

Tarraystring = array [0 .. 99] of string [255]

Tclient = packed record
Name: String [50];
Time: String [50];
HOST: String [50];
IP: String [50];
Mac: String [50];
MSG: tarraystring;
End;
Ptclient = ^ tclient;

... Write
Idtcpclient. writebuffer (fclientsend, sizeof (fclientsend), true );

... Read
Athread. Connection. readbuffer (client, sizeof (client ));

So how to use readfromstack? Can I use its return value to determine whether it has received the number of bytes that I need? For example, I can first determine whether there is a packet header that has received enough bytes and then read the packet header into the buffer?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.