Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create peer to peer Connection in java?

 
Sanchit Gupta
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create voice classrooms in java , it needs to make a peer to peer connection. Still i am using Socket Programming (TCP/IP) but its very time taking,
I can use UDP because we can not the IP of client .

So which connection i can create in java to send voice data to create voice classrooms over the WAN.
 
Shed Ansari
Greenhorn
Posts: 3
Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want run your application over WAN then TCP/IP is not sufficient. I think you have to use UDP protocol.
 
Shed Ansari
Greenhorn
Posts: 3
Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use JXTA protocol for peer to peer connection
 
Sanchit Gupta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give me any tutorial or example code to implement JXTA Protpcol ?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand the problem correctly, then what you have in place is built on sockets but it too slow. The first thing to note is that all other peer-to-peer approaches also use sockets, so if that's the cause of the slowness then you're out of luck. But we don't know that yet - you should start by measuring which aspect of your solution is (too) slow, and then try to improve those.

Since JXTA was mentioned, that's an XML messaging protocol - it is unlikely to be the right solution for sending voice data, and likely not fast enough, either. If you want to check it out, the Java implementation is at https://jxse.kenai.com/

Another P2P solution is Apache River, the successor to Jini and JavaSpaces, but it too is built for RPC, so probably not the right solution.

My gut feeling is that you need a Java implementation of RTP for this.
 
Sanchit Gupta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Problem is that - I want to create voice broadcasting in java. Since I am using TCP/IP socket to send voice from one client to other. But it is very slow and creating noise in voice transmission.
The architecture is like- client_1(Teacher)---> Server --->Client_2(Student) , just like an online classrooms.

Flow of process ------> whatever client_1(Teacher) speak is captured using TargetDataLine in a buffer of size[10 KB] then buffer is sent to server using socket programming(till now using TCP) then server send that buffer to client_2(Student) , where student can listen the buffer data by writing buffer on SourceDataLine.

Problem--> The module is working properly on LAN (All 3 module in same wired network) , but when we run it over the WAN , at Client_2(Student ) site there is noise in voice received from server.

Please give me the proper solution of this problem.

Thanks in advance.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it is not actually a P2P architecture, it is a client/server architecture.

If this was my problem I would start by investigating *why* there is noise. Is the data transmitted faithfully, meaning, does the exact same data arrive at the listener that is sent by the talker? If yes, I don't see why there would be additional noise. If no, investigate where (and why) the data is altered.
 
Sanchit Gupta
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think when packet travel through WAN , some garbage is add.
how can i count total number of packet send and receive , so that i can compare the number of packet send is equals to number of packets received?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on the specifics of the code (which we don't know), but since you mention SourceDataLine - that has a write method which writes a specific number of bytes. So you can certainly add up the number of bytes written. I would expect something similar to be possible on the receiving end.

It's possible that the number of bytes written and received stays the same, but that the content of those bytes gets corrupted. In that case you have to inspect the bytes themselves, instead of just counting their number.
 
Shed Ansari
Greenhorn
Posts: 3
Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell me, is that shuttering or noise. because As you explain your problem that you are using TCP/IP and TCP/IP is slow so shuttering will produce defiantly. According to me firstly you should establish a connection using TCP/IP and then send your voice using UDP.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic