Answer the question
In order to leave comments, you need to log in
Is it possible to send datagrams to UDP directly through the listening socket?
The situation is the following WinSocket API, the implementation in general on Delphi 6, while I'm more interested in the implementation at the Win Socket API level, although if anyone knows, it will not be worse in relation to Delphi.
The situation is the following. A UDP server socket has been created, bound to an address, waiting for messages in a separate thread.
A UDP message arrives on the server socket specified above. At this moment, I get the IP and port of the sender, after which I try to send a message using the listening server socket to the IP and port of the sender of the just received message, in general, this is the line:
SendRes:= sendto(FSocket,messageToSend[1],Length(messageToSend),0,SendAddr,SizeOf(SendAddr));//Тут значит следующие параметры указаны:
Answer the question
In order to leave comments, you need to log in
Partially understood.
Regarding the question: is it possible to send a message back to the client through the listening server socket: yes it is possible, it comes, the client receives.
With regards to why the client port on the client program is different from the client port in the server program - I don’t understand why, but they differ for me. And everything comes.
Here is a screenshot of the situation:
And the situation was that I didn’t send a message to the client via sendto - I found an error in the code, it turned out that I used the procedure on the button directly from the class, but I had to call it on an object instance, so it turned out that the server socket in that procedure was not initialized.
Sources of the client and server programs in Delphi and other details at the link blog.ivru.net/?id=199
__________________________________________ I'm
editing the answer because I found the reason why the ports were different:
__________________________________________
As it turned out, in the cases of the client program, I did not use ntohs to swap the high and low bytes of the port in the address variable, but in the cases of the server program I used ntohs. So we got integer numbers in one case, the junior and senior bytes went in one order and in the other in the reverse order.
The situation is described in more detail here https://ru.stackoverflow.com/questions/1137180/win...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question