waylonion
waylonion

Reputation: 6976

UDP or TCP for Android Audio Stream

My ultimate goal here is to stream a user's voice input into an Android device over to a Desktop application.

For the Android device, it will be obviously be running a java based Android application. For the Desktop application, I'm considering writing a Java applet to accept the stream.

These are the benefits and drawbacks of TCP and UDP as explained by Wikipedia

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.

I would like the user's voice stream to be uninterrupted and steady when the Android is transmitting it to the desktop application.

Beyond simply considering the benefits and drawbacks of the two different technologies as Wikipedia lists, what else should I be aware of when choosing a technology?

Which is the better choice UDP or TCP?

Upvotes: 3

Views: 1795

Answers (2)

topcbl
topcbl

Reputation: 849

In my opinion, it also rely on your project's specification. The lost of signal is acceptable or not. UDP is extremely faster than TCP which is suitable to stream a user's voice input. It looks like traditional telephone call, sometime you hear some "noise" but the call is still good enough for us to use. Moreover, using TCP would bring you a significant delay and UDP was born for streaming.

Upvotes: 2

Shawerma
Shawerma

Reputation: 131

UDP. Since you are streaming, you don't need to retransmit packets every time they are lost which would cause more delay as in TCP. https://www.onsip.com/blog/udp-versus-tcp-for-voip

But, you can implement it over TCP with a network buffer, so the delay will be noticeable at first, and then the user will be provided with a smooth play-out.

Upvotes: 0

Related Questions