Skip to main content

Help needed please

5 replies [Last post]
aymanshargawi
Offline
Joined: 2009-05-31

I have developed two peers; one as a service requestor and the other as a service distributor. Service here implies the transfer of a package of files from the distributor peer to the requestor peer.

The problem I am having right now is how to get these two peers to see one another over the network. When I have both peers on the same machine, it just works fine. The requestor publishes an advertisement and the distributor finds it and connets to the requestor and starts talking to it.

I want the same senario to happen when the peers are not on the same machine, however these machines are part of a LAN.

Any hint what I might be missing here or just might have done wrong?

Thanks and regards,

Ayman

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
aymanshargawi
Offline
Joined: 2009-05-31

OK I have figured why it does not work. That's because the LAN on which these two peers reside blocks most ports from communicating by default except for the email system and stuff.

What I did was set up an isolated LAN and tested the system. The result was a complete success.

Thank you for trying to help out.

Ayman

flyroom
Offline
Joined: 2008-11-24

Maybe you could post the complete error or waring message which could help to identify the causes.
from my experience,if two peers could find each other on the same machine,they could work well in the same subnet with default configuration.It's necessary to configure when it's time to communicate across subnet.
It sames that by default,two peers find each other by means of multicasting which annouce itself to all the nodes in the same subnet

aymanshargawi
Offline
Joined: 2009-05-31

Thank you for replying.

The two peers are configured exactly the same and each one runs on its machine with no problems or errors. Only thing is that when one publishes its pipe advertisement, the other one just does not find it; however, it finds it if they were instantiated on the same machine.!

Could it be the security policy of the LAN on which these two peers reside?

This is the instantiaion code in both peers that connects them to the network and makes them part of the netPeerGroup.

public PeerGroup connectToJxta(NetworkManager manager)
{
try
{
manager = new NetworkManager(NetworkManager.ConfigMode.ADHOC, this.getPeerName(),
new File(new File("local"), this.getPeerName()).toURI());
manager.startNetwork();
netPeerGroup = manager.getNetPeerGroup();
return netPeerGroup;
}
catch(Exception e)
{
lastErr = "Unable to Connect to JXTA Network for the following reason:\n" + e.getMessage();
e.printStackTrace();
return null;
}
}

Hope that will give you a hint of how it is set up to work.

Ayman

deniswsrosa
Offline
Joined: 2006-05-05

Hi! please, post the code of how you publish your adv and how you get it, it seems like a publish mistake.

aymanshargawi
Offline
Joined: 2009-05-31

Although it works when I start it on the same machine, but this is the code to publish the adv anyways:

public boolean publishPipeAdvertisement(PipeAdvertisement pipeAdv)
{

long lifetime = 60 * 2 * 1000L;
long expiration = 60 * 2 * 1000L;

discoveryService = getDiscoveryService(netPeerGroup);
if(null != discoveryService)
{
try
{

if(!getLastPublishedAd().equals(pipeAdv.getName()))
{
discoveryService.publish(pipeAdv, lifetime, expiration);
display.append( "\n"+pipeAdv.getName() + " ID: " + pipeAdv.getPipeID() + " is published locally\n");

discoveryService.remotePublish(pipeAdv,expiration);
display.append( "\n"+pipeAdv.getName() + " ID: " + pipeAdv.getPipeID() + " is published remotely\n");
setLastPublishedAd(pipeAdv.getName());
}

return true;
}
catch(Exception e)
{
lastErr = "Unable to Publish the Input Pipe for the following reason:\n" + e.getMessage();
e.printStackTrace();
return false;
}

}
else
return false;

}

This is the code to find the adv:

private Advertisement findAdvertisement(String crit, String val)throws IOException
{
Enumeration localAdv = null;

long lifetime = 60 * 2 * 1000L;
long expiration = 60 * 2 * 1000L;
long waittime = 60 * 3 * 1000L;

try
{
if(getDiscoveryService(netPeerGroup)!= null)
{
display.append("\nI am here in findAdvertisement looking for " + crit + " = " + val+ "\n");
discoveryService.getLocalAdvertisements(discoveryService.ADV,crit, val);
if((localAdv != null) && localAdv.hasMoreElements())
{
display.append("\nlocalAdv is not null\n");
PipeAdvertisement temp = (PipeAdvertisement)localAdv.nextElement();
if(temp.getName().equals(val))
{
return temp;
}
else
{
display.append("\nlocalAdv is null and now attempting to get remote advs\n");

discoveryService.getRemoteAdvertisements(// no specific peer (propagate)
null, // Adv type
DiscoveryService.ADV, // Attribute = any
crit, // Value = any
val, // one advertisement response is all we are looking for
1, // no query specific listener. we are using a global listener
this);

return null;
}

}
else
{
display.append("\nlocalAdv is null and now attempting to get remote advs\n");

discoveryService.getRemoteAdvertisements(// no specific peer (propagate)
null, // Adv type
DiscoveryService.ADV, // Attribute = any
crit, // Value = any
val, // one advertisement response is all we are looking for
1, // no query specific listener. we are using a global listener
this);

return null;

}
}
else
{
lastErr = "DiscoveryService is not available";
throw new IOException("DiscoveryService is null");

}
}
catch(Exception e)
{
lastErr = "Unable to Find advertisemetns for the following reason:\n" + e.getMessage();
e.printStackTrace();
return null;
}

}

I'll be gone for now. I'll check your reply when I'm back.

Thanks for helping out.

Ayman