java - Android 音频流的 UDP 或 TCP

标签 java android sockets audio tcp

我的最终目标是将用户的语音输入流式传输到 Android 设备再到桌面应用程序。

对于 Android 设备,显然会运行基于 Java 的 Android 应用程序。对于桌面应用程序,我正在考虑编写一个 Java 小程序来接受流。

这些是维基百科解释的 TCP 和 UDP 的优点和缺点

Transmission Control Protocol is a connection-oriented protocol, which means that it requires handshaking to set up end-to-end communications. Once a connection is set up, user data may be sent bi-directionally over the connection.

Reliable – TCP manages message acknowledgment, retransmission and timeout. Multiple attempts to deliver the message are made. If it gets lost along the way, the server will re-request the lost part. In TCP, there's either no missing data, or, in case of multiple timeouts, the connection is dropped. Ordered – If two messages are sent over a connection in sequence, the first message will reach the receiving application first. When data segments arrive in the wrong order, TCP buffers delay the out-of-order data until all data can be properly re-ordered and delivered to the application. Heavyweight – TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control. Streaming – Data is read as a byte stream, no distinguishing indications are transmitted to signal message (segment) boundaries. User Datagram Protocol is a simpler message-based connectionless protocol. Connectionless protocols do not set up a dedicated end-to-end connection. Communication is achieved by transmitting information in one direction from source to destination without verifying the readiness or state of the receiver.

Unreliable – When a UDP message is sent, it cannot be known if it will reach its destination; it could get lost along the way. There is no concept of acknowledgment, retransmission, or timeout. Not ordered – If two messages are sent to the same recipient, the order in which they arrive cannot be predicted. Lightweight – There is no ordering of messages, no tracking connections, etc. It is a small transport layer designed on top of IP. Datagrams – Packets are sent individually and are checked for integrity only if they arrive. Packets have definite boundaries which are honored upon receipt, meaning a read operation at the receiver socket will yield an entire message as it was originally sent. No congestion control – UDP itself does not avoid congestion. Congestion control measures must be implemented at the application level. Broadcasts - being connectionless, UDP can broadcast - sent packets can be addressed to be receivable by all devices on the subnet.

我希望 Android 将用户的语音流传输到桌面应用程序时不间断且稳定。

除了像维基百科列出的那样简单地考虑两种不同技术的优缺点,在选择技术时我还应该注意什么?

UDP 和 TCP 哪个更好?

最佳答案

在我看来,它还取决于您的项目规范。信号丢失是否可以接受。 UDP 比 TCP 快得多,适合流式传输用户的语音输入。它看起来像传统的电话,有时您会听到一些“噪音”,但通话仍然足够我们使用。此外,使用 TCP 会带来明显的延迟,而 UDP 是为流媒体而生的。

关于java - Android 音频流的 UDP 或 TCP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35261909/

相关文章:

android - 重力底部不适用于相对布局内的textview

java - InputStream 跳过字节

php - node.js 中的基本 smtp 服务器

java - 如何使用带有实现依赖项的 Gradle 创建可执行的胖 JAR?

java - 如何在android中将多个记录从一个 Activity 传递到另一个 Activity ?

java - 使用 HTMLUnit 从 url 保存图像

android dumpsys batteryinfo 与 android dumpsys batterystats

android - 与抽屉导航一起使用时,工具栏后退按钮不起作用

java - 通过 Socket 在 C++ 和 Java 之间传输图像

Java 应用程序未使用正确的用户名/密码连接到 Oracle 数据库