Caroll Mitchel
Caroll Mitchel

Reputation: 19

UDP, datagrams and sound in java

I need an example code of sending UDP sound packets, like using datagrams to send audio from server, who record the audio by the microphone, to a client, who only listen the audio. Can someone help me please? I have found really good examples, but they all use TCP and Sockets (like this one http://www.developer.com/java/other/print.php/2105421), not DatagramSocket, i would really appreciate your help.

Upvotes: 1

Views: 2738

Answers (2)

Johnydep
Johnydep

Reputation: 6277

Give these Links a try:

  1. Simplistic Java music broadcasting over UDP
  2. TCP/IP, UDP & Multicasting Through Java's Socket
  3. Check this Interactive Telephony Article, specially the Streaming Class Example

And then read little about DatagramSocket Class in Java. This tutorial should definitively help.

Upvotes: 0

Paul Sullivan
Paul Sullivan

Reputation: 2875

Sending via UDP is a bit silly. UDP can arrive in any order and has no sequencing in the protocol. This means you may or may not receive a packet and you may receive packet two before one and have no way of knowing (without having written some code to sequence them) which is first.

Drop UDP and use TCP.

EDIT:

Okay assuming you must use UDP then roughly I would do it like this (assuming you can send a UDP packet)

1) create scheme of data to be encapsulated in UDP of the following data

Packet sequence number Data Crc checksum

2) on the clientside you will need a buffer to order and reassemble the data

This will buffer the packets, order and at a given buffer length reassemble the data (either inserting no audio or truncating where missing sequence numbers are)

You would need to have also worked out what the bit rate is considering the weakest connection. It is better to lose granularity of sound than have very clear snippets of sound.

Note. The crc could also be combined with data length.

Hth

Upvotes: 3

Related Questions