Reputation: 19
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
Reputation: 6277
Give these Links a try:
And then read little about DatagramSocket Class in Java. This tutorial should definitively help.
Upvotes: 0
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