For the seed - component Indy - IdUDPClient. In the near future I plan to rewrite under the API, but nevertheless, even a quick googling on the API of sockets did not suggest how you can find out the length of the input packet.

True, looking at the incoming packets with a sniffer, I realized that the first 20 bytes contain information about this packet, including and its length, but I do not know how to parse it. Tell me?

  • IdUDPClient-> ReceiveBuffer () ??? Not? One of the parameters is the size of the buffer. - Dex
  • Well ... you specify this parameter yourself, therefore at random - not what is required. - DizzWebS
  • What do you mean yourself? You get a buffer, and its size. - Dex
  • In my program it looks like this: Sysutils :: TBytes ReceiveBuff; ReceiveBuff.set_length (1000); char * gstats = "\ xff \ xff \ xff \ xff getstatus"; IdUDPClient1-> SendBuffer (RawToBytes (gstats, strlen (gstats))); IdUDPClient1-> ReceiveBuffer (ReceiveBuff, 500); // here we take the buffer FOR THE TIME specified by the second parameter. Now I’ll look in the builder, maybe the functions can be fed some parameters, although if there is a function to get the size of the input packet, then this is excellent. - DizzWebS
  • By the way, I found this solution in the internet, and I have a lot of TBytes ReceiveBuff tied to it, which, it seems to me, is not very good, and somehow I can do without it, but I don’t know how. Therefore, in general, I want to abandon indie and redo the API functions of Windows. At the same time better understand sockets. - DizzWebS

1 answer 1

In recvfrom (sock, buf, bufsize, flags, & from, & fromlen), we ask for a large number (bufsize) (into a large buffer). Large means more than the maximum possible UDP packet. Return the length of the next packet and put it in the buffer. In from and fromlen returns the server address (IP: Port) and the length of this address (well, for IP it is not interesting). Learn more man 2 recvfrom. In principle, in Windows db. is very similar.

  • In my case, the buffer is set, then a command is sent to the server, a response is received in the form of a packet, and placed in the buffer. And in the end, I get the information that came from the server + garbage for driving the buffer. The truth is the only thing - the strange thing is that this alleged "garbage" is always in the form of the same symbols. - DizzWebS
  • And another thing is strange - I have a timer to send and receive, and for the first time the infa with garbage is in the buffer, and the next ones are already fine ... Maybe I missed something somewhere ?! - DizzWebS
  • Use sockets (C or C ++) - avp
  • Looks like I'll do it. - DizzWebS