I am trying to use TUdpSocket in Delphi. I want to connect to a UDP server, send some data and wait for a response. The data is sent correctly, but the control does not receive anything. I do not know why. I have been struggling with this problem for many years, and I am going to refuse: - (.
I tried to use TIdUDPClient, but the situation is the same. Data is sent correctly but not accepted.
Only TIdUDPServer works more or less correctly, as it sends and receives data. Unfortunately, data reception is processed by a separate stream (main or different, depending on the ThreadedEvent property), which forces me to use synchronization and complicate the whole code. I would like to handle a UDP connection in my thread. Just send some data and call WaitForData () to wait for a response, and then process it in the same thread.
And if this is not possible, I do not want to use third-party controls, but if this is the only solution, I accept it.
Thank you very much for your help in advance.
---- Examples ---
i) TUDPSocket:
var lR, lW, lE: boolean; begin UdpSocket1.LocalPort := '1600'; UdpSocket1.RemotePort := '1600'; UdpSocket1.RemoteHost := '127.0.0.1'; UdpSocket1.Connect; UdpSocket1.Sendln('test'); UdpSocket1.Select(@lR, @lW, @lE, 2000); if lR then ShowMessage(UdpSocket1.Receiveln()); end;
As you can see, the control should receive the data that it passes. And apparently this is so, since lR evaluates to true after calling the Select () method. But Receiveln () returns an empty string, as ReceiveBuf () does. When I start the UDP server and send it some data, it is received correctly, so I'm sure that the data is really sent.