移动消息服务使用 TCP 还是 UDP?

发布于 2024-12-02 21:10:28 字数 237 浏览 0 评论 0原文

我正在开发一个使用java用于消息服务(P2P)的移动应用程序,我仍处于早期阶段,并正在寻找最适合此类应用程序的协议。正如我所发现的。套接字编程比 Web 服务更好。如您所知,它不需要为发送的消息添加额外的数据(开销),因此成本会更低。

除了套接字之外还有第三种选择吗? HTTP?

socket是选择什么是最好使用TCP或UDP?!

这个问题对于任何其他选项都是开放的,而不仅仅是这里提到的选项 提前谢谢你

I am working on developing a mobile application using java for messaging services(P2P) I am still in the early stages, and searching about the best and most suitable protocol for such application. As I have found. socket programming is better than web services. as you know it doesn't need to add extra data (overhead) for the sent message so it will cost lower.

Is there a third option other than sockets & HTTP?

Is socket is the choice what is the best to use TCP or UDP ?!

The question is open for any other options not only the what is mentioned here
and thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可遇━不可求 2024-12-09 21:10:28

HTTP 和 TCP/UDP 位于通信系统模型的不同层(最流行的两个是 OSI 模型和 TCP/IP 模型)。 HTTP 是建立在套接字之上的(这就是为什么会有额外开销的原因),因此从技术上来说,它们并不是不同的解决方案。

使用 HTTP 将为您带来拥有大量库、文档和示例可供使用的优势,而编写您自己的自定义协议可能需要花费更多时间和精力,但可能会更轻松。

如果您选择原始套接字...我无法告诉您是否应该使用 TCP 还是 UDP - 这取决于很多因素,但基本区别在于,如果有可用连接或存在可用连接,则 TCP 连接将保证成功传送如果没有,则出现错误消息,而 UDP 只是发送数据,并不关心数据是否到达(例如,对于流式直播视频,确保每一位数据都被传输是没有意义的,因为 1 秒后就不再传输)相关的)。

没有正确或错误的答案 - 您只需要考虑所有涉及的因素并仔细设计整个过程。

HTTP and TCP/UDP reside in different layers of the communications systems models (the two most popular being the OSI model and the TCP/IP model). HTTP is built on top of sockets (that's why there's additional overhead), so technically - they are not different solutions.

Using HTTP will give you the advantage of having lots of libraries, documentation and examples to use, while writing your own, custom protocol might take a lot more time and efforts, but would probably be lighter.

If you opt for raw sockets ... I can't tell you if you should use TCP or UDP - that depends on lots of factors, but the basic difference is that a TCP connection would guarantee a successful delivery if there's connectivity available or an error message if not, while UDP just sends the data and doesn't care if it gets there or not (e.g. for streaming live video, there's no point in ensuring that every bit of data is being transferred, as 1 second later it's no longer relevant).

There's no right or wrong answer - you just need to consider all the factors involved and carefully design the whole process.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文