Skip to main content

JXTA socket client-server example

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2011-11-05


In the tutorial client-server socket in the following key code:

while (true) {

try {

System.out.println("Waiting for connections");

Socket socket = serverSocket.accept();

if (socket != null) {

System.out.println("New connection appeared");

Thread thread = new Thread(new ConnectionToClient(socket), "Connection Handler Thread");



}catch (Exception e) {


My question is if there are 2 clients that connect to the server, do they have different sockets? If yes is it possible to have different pipes between a client and the 2 servers?

Waiting for your anwser.


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2011-08-10

you want to run 2 clients which connect to the same server? In my understanding, you do need to establish two different sockets.

if you read the examples carefully, you will find these code bellow on a client:

// Creating the JXTA socket
JxtaSocket MySocket = new JxtaSocket(NetPeerGroup, null,
30000, true);

it is shown that a client uses the server's pipeAdvertisement to create a connection to server. When you have another client wants to establish one communication to that server, it should use the same advertisement, because if the later client uses a new pipeAdvertisement that server doesn't have, it will fail to establish such a socket.

According the description above, here comes problem: Only the advertisement which both server and client know can be used in creating a socket. So, if you want establish second socket to server, you shoud make both the server and the later client have a same pipeAdvertisment.