0

I want to create a voice chat application in pure java socket programming. I used UDP protocol to transfer recorded voice from one client to another but when i test it over the internet voice is not comming continuously. As i am new to this voice chat application, someone may suggest what should i do for getting continuous voice.

The Scenario is like this.

Flow of voice chat as this shows only one way communication-

FLOW of data

Client1------------------------------>> Server ------------------------------------>>Client2

Client1: Reading 1KB voice buffer from TargateDataLine then create a voice packet and sent to server.

Server: Receive from client1 and then send to client2.

Client2: Receive the UDP packet and get voice data then play.


Also facing the bandwidth up and down problem. What should be the minimum bandwidth to use voice chat. Ex- skype required 30KBPS udloading/downloading speed.

Thanks in advance.

user2717794
  • 1
  • 1
  • 3
  • I don't think it's a good way to start this from scratch, there are hundred of open source library available. – CharlesX Sep 10 '14 at 10:58
  • Because of the latency in the JavaSound API, it is also quite difficult (if not impossible) to implement voice chat with reasonable performance in Java. – jarnbjo Sep 10 '14 at 12:07
  • Mr. @chariesX Can you refer these libraries for implementing voice transmission over the internet(WAN). – user2717794 Sep 10 '14 at 12:07

3 Answers3

1

In order to establish a connection between two or more users for peer-to-peer communication you need a signaling server as well as STUN/TURN servers.

You can code your own ones or use a ready backend solutions like ConnectyCube and concentrate on client-side implementation. Here are some WebRTC video chat code samples for your reference as well.

0

You should send the packets directly between the clients. The relaying of packets through the server is adding more delay to it. Simply send it from client1 to client2.

Kunjan Thadani
  • 1,660
  • 3
  • 18
  • 26
  • can you give me an example -how to connect client1 with client2 without any server in java (for voice chat). – user2717794 Sep 15 '14 at 10:40
  • You will need the server for initiating the connection between the clients. Refer this link for the concept and a small piece of code- http://stackoverflow.com/questions/19087036/udp-holepunching-behind-nat/21979176#21979176 – Kunjan Thadani Sep 15 '14 at 17:01
0

The Answer is pretty simple you should use tcp protocol. Coz udp sends the packet but doesn't ensure that the packet was received by the target. but tcp protocol ensures it and you will get a stable connection with cost of some speed reduced in transfer of data.tcp vs udp