使用哪种协议通过 LAN 开发聊天应用程序?
我想用 C++ 创建一个聊天应用程序(桌面应用程序),所以我需要研究和实现哪个协议。 UDP(?)
请给我一些好的想法和建议以及链接。
I would like to create a chat application(desktop-app) in c++, so which protocol i would need to study and implement. UDP(?)
Please provide me some good thoughts and advices and links also.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
UDP协议并不是互联网聊天程序的最佳选择。 UDP 数据包将被代理阻止。并且 UDP 不保证数据包的传送。所以TCP协议可能是更好的选择。
查看 Boost.Asio 库。它已经包含聊天程序的原始实现。
UDP protocol is not the best choice for Internet chat program. UDP packets will be blocked by proxies. And UDP doesn't guarantee packets delivery. So probably TCP protocol will be a better choice.
Take a look on Boost.Asio Library. It already contains primitive implementation of chat program.
您在这里没有给我们太多细节!
如果您的目的确实是制作一个功能齐全且功能齐全的聊天应用程序,我建议您查看 XMPP 这是一个开放的即时通讯协议。 这里是一些实现它的库的列表。
例如,如果您的目的是学习网络编程,并且您对 UDP 比 TCP 更感兴趣,那么 UDP 对于聊天应用程序来说是一个糟糕的选择,因为它不能保证太多数据完整性或顺序。您的消息可能(并且将会!)以错误的顺序收到,甚至有些消息可能会丢失。 TCP 会为您做一些检查。
在这之间(一个非常简单的聊天应用程序),您可以实现自己的协议并使用其他人在这里建议的库,例如 Boost.asio, ACE 、POCO,甚至wxWidgets 和 Qt,这将简化套接字处理并提供为过去 2 构建桌面应用程序需要什么。
You don't give us much details here!
If your purpose is really to make a fully working and feature full chat application I suggest you look at XMPP which is an open instant-messenging protocol. Here is a list of some libraries implementing it.
If your purpose is to study network programming and you're more interested in UDP versus TCP for instance, then UDP is a bad choice for a chat application as it does not guarantee much about data integrity or ordering. Your messages might (and will!) be received in bad order or some might even be missing. TCP does that for kind of check for you.
In between (a very simple chat app) you can implement your very own protocol and use libraries others have suggested here like Boost.asio, ACE, POCO, or even wxWidgets and Qt, which will ease socket handling and also provide what you need to build a desktop app for the last 2.
尝试使用 Boost.Asio。其中包含一些聊天应用程序示例在文档中。
Try using Boost.Asio. There are some examples of chat applications included in documentation.
您可以使用或查看开源网络库,例如 ACE。那里有很多好东西。
You can use or look at an open-source networking library like ACE. A lot of goodies there.
您可以使用处理即时消息协议的现有库,例如
libpurple
。You could use an existing library that handles instant messaging protocols, such as
libpurple
.UDP 类似于“一劳永逸”的协议。它速度很快,但如果您使用它通过互联网进行通信,则根本无法保证您的消息会被收到。即使是 LAN,您的数据包仍然可能丢失。使用 TCP 会更方便,它可以确保您的数据包按照您发送的顺序准确无误地到达。
UDP is like a 'shoot and forget' kind of protocol. It's fast, but if you use it for communicating over the internet, there's no guarantee your messages will be recieved at all. Even if it's LAN, your packets can still be lost. It would be more convenient to use TCP which makes sure your packets arrive without errors and in the order you sent them.