我应该害怕使用UDP来进行客户端/服务器广播对话吗? [英] Should I be afraid to use UDP to make a client/server broadcast talk?

查看:148
本文介绍了我应该害怕使用UDP来进行客户端/服务器广播对话吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了最后两天阅读有关Indy TCP的每个 StackOverflow 问题和答案(当然还有 googling UDP 协议,以便确定在用户应用程序和Windows服务之间的通信方式中应该使用哪种协议。

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.

从到目前为止的情况来看, UDP 是最简单的,也是我设法从<$ c接收广播消息的唯一方法$ c> TidUDPClient (我还没有测试响应)。而且我还注意到 TCP 的线程循环稍微复杂一些。

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.

UDP 不可靠, UDP 不可靠... 我开始怀疑是否最好还是使用 TCP

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.

我的用户应用程序将在许多计算机上运行,​​并且服务将在其中之一中运行,与客户共享一个 IP 或在专用机器上运行,具体取决于我客户的资金。因此,我真的应该担心 UDP 数据丢失的可能性吗?

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?

我需要广播功能,因此我的服务器可以为所有用户提供建议客户端立即了解应用程序更新,当然,如果我的客户端应用程序不知道服务/服务器在哪个 IP 中,它将发送广播呼叫以告知服务器在哪里。这是否适用于 TCP

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.

e86c6234bf117b97d6d4a0c5c317bbc75a3282dfd34b95446fc6e26d46239327f2f1db352b2f796e95dccd9> >

e86c6234bf117b97d6d4a0c5c317bbc75a3282dfd34b95446fc6e26d46239327f2f1db352b2f796e95dccd9f99403adf5eda7ba8

推荐答案

我决定同时使用它们!

简单用例:

为了与 TCP 协议进行通信,您必须建立一个可以拥有的连接仅当您知道两端的 IP Port 时。

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.

如果在加载应用程序时没有该信息,则可以使用 UDP 广播 IP 地址和您打算查找服务器的意图。您可以尝试5次左右,然后再向用户提出一条错误消息,提示您找不到服务器或服务器已关闭。

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.

在<$ c中发送该消息$ c> UDP 将(一次或多次)到达服务器的 UDP 耳,该服务器现在将从寂寞的客户端的 IP ,现在将通过 TCP 开始正确的连接,以阅读有关应用程序关键消息的内容。

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?

这篇关于我应该害怕使用UDP来进行客户端/服务器广播对话吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆