问题
I spent the last two days reading each StackOverflow
questions and answers (and googling of course) about Indy TCP
and UDP
protocol in order to decide which one should I use in my communication method between my User Application and my Windows Service.
From what I saw so far, UDP
is the easiest and the only one I managed to work to receive broadcast messages from TidUDPClient
(I did not testes the response back yet). And I also noticed that TCP
is a bit more complicated with it's thread loop.
But since everywhere I am told UDP
is not reliable, UDP
is not reliable... I begin to wonder if it's not better to use TCP
anyway.
My User Application will be running on many machines, and the Service will be running in one of them, sharing one IP
with a Client, or in a dedicated machine, depending on my client's funds. So, should I really be worried about UDP
data loss possibilities?
I need broadcast capabilities so my server advises all clients at once about Application updates, and of course, if my the Client Application does not know in which IP
the Service/Server is, it will send a broadcast call to be told where the server is. Is that applicable to TCP
?
The messages I am sending are requests for users access confirmation, users privileges, and application executable file updates, since the main application can't update itself. Those messages are encrypted like below, and they might bet bigger sometimes.
e86c6234bf117b97d6d4a0c5c317bbc75a3282dfd34b95446fc6e26d46239327f2f1db352b2f796e95dccd9f99403adf5eda7ba8
回答1:
I decided to use them both!
Simple use case:
In order to communicate with TCP
prococol you have to establish a connection which you can have only if you know IP
and Port
on both ends.
If you do not have that information when you load your Application, then you use the UDP
to Broadcast your IP
address and your intention to find the/a Server. You may try about 5 times before you raise the user an error telling that you did not find the Server or that the Server is down.
Sending that message in UDP
will (one time or other) reach the UDP
ear of the Server, which will now know the IP from the lonely Client's IP
and will now begin a proper connection via TCP
to be read talk about the critical messages of the Application.
What do you think of that approach?
来源:https://stackoverflow.com/questions/18069948/should-i-be-afraid-to-use-udp-to-make-a-client-server-broadcast-talk