trouble finding peers
Lucas L Jordan <[email protected]> Thu, 03 Nov 2005 19:38:43 -0500
| Newsgroups | gmane.comp.java.jxta.user |
|---|---|
| Message-ID | <[email protected]> |
Greetings
My goal is to create a PeerGroup and then have two clients discover it,
join it and then find each other.
I can create a PeerGroup, that is simple enough but here is how I am
doing it anyway:
protected PeerGroup createGroup() throws Exception {
System.out.println("Creating group");
DiscoveryService discovery = netPeerGroup.getDiscoveryService();
ModuleImplAdvertisement implAdv =
netPeerGroup.getAllPurposePeerGroupImplAdvertisement();
PeerGroup newGroup = netPeerGroup.newGroup(null, implAdv,
"fjord:game:group1", "The Root group for all Fjord Games");
PeerGroupAdvertisement adv = newGroup.getPeerGroupAdvertisement
();
discovery.remotePublish(adv);
return newGroup;
}
I then discover this group like this:
discovery.getRemoteAdvertisements(null, DiscoveryService.GROUP, "Name",
"fjord:game:group1", 5, new DiscoveryListener() {
public void discoveryEvent(DiscoveryEvent ev) {
DiscoveryResponseMsg res = ev.getResponse();
PeerGroupAdvertisement adv = null;
Enumeration en = res.getAdvertisements();
if (en != null ) {
while (en.hasMoreElements()) {
adv = (PeerGroupAdvertisement) en.nextElement();
PeerGroupID peerGroupId = adv.getPeerGroupID();
try {
gamePeerGroup = netPeerGroup.newGroup(adv);
System.out.println("game group found.");
} catch (PeerGroupException ex) {
ex.printStackTrace();
}
}
}
}
});
and then I join the group like this:
embershipService membership = gamePeerGroup.getMembershipService();
StructuredDocument creds = null;
AuthenticationCredential authCred =
new AuthenticationCredential( gamePeerGroup, null,
creds );
Authenticator auth = membership.apply( authCred );
System.out.println("auth.isReadyForJoin(): " +
auth.isReadyForJoin());
Credential myCred = membership.join(auth);
System.out.println("Joined Group");
so I don't really know how test that I have actually joined. But
assuming that I did, this is how I am looking for other peers in that
PeerGroup:
Runnable runnable = new Runnable(){
public void run(){
while(true){
DiscoveryService disc =
gamePeerGroup.getDiscoveryService();
disc.getRemoteAdvertisements(null,
DiscoveryService.PEER,
null, null, 1, new DiscoveryListener() {
public void discoveryEvent(DiscoveryEvent
discoveryEvent) {
Enumeration resultEnum =
discoveryEvent.getSearchResults();
if (resultEnum.hasMoreElements()){
System.out.println("No players Found,
zero entrys");
}
if (resultEnum != null){
while(resultEnum.hasMoreElements()){
PeerAdvertisement peer =
(PeerAdvertisement) resultEnum.nextElement();
enqueueMessage(new
GameMessage.PlayerFound(GameProject.this, peer));
}
}else{
System.out.println("No players Found");
}
}
});
System.out.println("Looking For Players");
Framework.sleep(20*1000);
}
}
};
I of course run this runnable in the background.
So when I run all this code, I create a group (if I don't find one after
a few min), I join it (i think), but I can't seem to find the other peer
in the group.
what am I doing wrong?
Thanks!
-Lucas