Communication protocols in UDP
After many hours, I found that the following steps are required to successfully communicate with this udp server:
1- Send "Initial message" on this port
2- Wait to receive from the server on any port
3- Then the port intended for sending further data to the server is equal to the port you received on it + 1
So my question is, is this kind of a known protocol / handshake, or is it just for this server?
PS: All the above posts were on udp sockets in C #
PS: Related to the previous question: About C # UDP sockets
thanks
a source to share
There is no dedicated UDP handshake β each UDP service specifies its own if needed. However, typically, the server does not expect the client to be able to listen on all of its ports at the same time. If you mean that the client is expecting messages from any port on the server, to the port the client sent the start message to, then that makes much more sense - and very close to how TFTP works. (The only difference I see so far is that TFTP doesn't do "+1".)
a source to share
The server effectively listens on a "well-known port" and then forwards subsequent messages to a dedicated port for each client. The requirement to send by the client to port + 1 is a bit strange
Client 192.168.0.1 - port 12121 ------------------------> Server 192.168.0.2 - port 5050
Client 192.168.0.1 - port 12121 <------------------------ Server 192.168.0.2 - port 23232
Client 192.168.0.1 - port 12121 ------------------------> Server 192.168.0.2 - port 23232 + 1
<------------------------ Server 192.168.0.2 - port 23232
------------------------> Server 192.168.0.2 - port 23232 + 1
The server probably does it in such a way that it doesn't need to demultiplex incoming clients data based on the client's address / port. Doing this is a little more efficient (usually) and also has some advantages depending on the design of the server, since the server has a socket that you have dedicated, which means if they do overlapping I / O then the socket stays the same for the entire period. exchanging messages with you, which makes it easier and more efficient to bind data to the socket (in this way they can probably avoid any lookups or blocking to process each datagram). This is enough anyway (see here if you want to know why I does it this way).
From your point of view, as a client (and I assume there are asynchronous sockets here) you need a Bind()
local socket first (just use INADDR_ANY
and 0
to let the OS choose the port for you) then release RecvFrom()
to the socket (so no information is sent between you to the server on that socket and it sends you data before you fetch recv). Then output SendTo()
to the "well known port" of the server. The server will then send you some data, and yours RecvFrom()
will return you the data and address that the server sent you. Then you can take this address, add it to the port, store this address and then send SendTo()
to this new send address, continuing to emit RecvFrom()
server data to read; or you can do something smart withConnect()
to bind the remote end of the socket to the "send to address" server and just use Write()
it RecvFrom()
from now on.
a source to share