Skip to main content

problems in searching for pipeAdvertisements

13 replies [Last post]
papelito
Offline
Joined: 2007-01-11

I'm doing very simple examples with jxta, but neverthless i'm having some problems...
In this example the client tries to search a pipe advertisement published by the server, but he doesn't find it. Can someone explain me why??

I post you both the server and the client code.

ServerCode:

import java.util.Enumeration;

import net.jxta.discovery.DiscoveryService;
import net.jxta.discovery.DiscoveryListener;
import net.jxta.discovery.DiscoveryEvent;
import net.jxta.document.AdvertisementFactory;
import net.jxta.endpoint.Message;
import net.jxta.endpoint.MessageElement;
import net.jxta.endpoint.Message.ElementIterator;
import net.jxta.peergroup.PeerGroup;
import net.jxta.peergroup.PeerGroupFactory;
import net.jxta.pipe.InputPipe;
import net.jxta.pipe.PipeMsgEvent;
import net.jxta.pipe.PipeMsgListener;
import net.jxta.pipe.PipeService;
import net.jxta.protocol.PipeAdvertisement;
import net.jxta.id.IDFactory;

public class PipeServer implements PipeMsgListener {

static PeerGroup netPeerGroup = null;
private DiscoveryService discovery;
private PipeService pipe;
private PipeAdvertisement pipeAdv;
private InputPipe pipeIn = null;

public static void main(String args[]) {
PipeServer myapp = new PipeServer();
myapp.startJxta();
}

private void startJxta() {
try {
netPeerGroup = PeerGroupFactory.newNetPeerGroup();
pipe = netPeerGroup.getPipeService();
discovery = netPeerGroup.getDiscoveryService();
pipeAdv = (PipeAdvertisement)AdvertisementFactory.newAdvertisement(PipeAdvertisement.getAdvertisementType());
pipeAdv.setPipeID(IDFactory.newPipeID(netPeerGroup.getPeerGroupID()));
pipeAdv.setName("testPipe");
pipeAdv.setType(PipeService.UnicastType);
discovery.publish(pipeAdv,PeerGroup.DEFAULT_LIFETIME,PeerGroup.DEFAULT_EXPIRATION);
discovery.remotePublish(pipeAdv,PeerGroup.DEFAULT_EXPIRATION);
System.out.println("Created and published the Pipe Advertisement");
pipeIn = pipe.createInputPipe(pipeAdv, this);
System.out.println("Waiting for msgs on input pipe...");
}
catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}

public void pipeMsgEvent(PipeMsgEvent event) {
Message msg=null;
Message.ElementIterator it=null;
MessageElement el=null;
String eName=null;
try {// grab the message from the event
msg = event.getMessage();
it = msg.getMessageElements();
while(it.hasNext()){
el = (MessageElement) it.next();
eName = el.getElementName();
System.out.println("Element Name: " +eName);
System.out.println("Element Value: "+el);
}
}catch (Exception e) {
e.printStackTrace();
return;
}
}
}

Client code:
import java.io.*;
import java.util.*;

import net.jxta.discovery.DiscoveryService;
import net.jxta.document.AdvertisementFactory;
import net.jxta.document.MimeMediaType;
import net.jxta.endpoint.Message;
import net.jxta.endpoint.StringMessageElement;
import net.jxta.exception.PeerGroupException;
import net.jxta.peergroup.PeerGroup;
import net.jxta.peergroup.PeerGroupFactory;
import net.jxta.pipe.OutputPipe;
import net.jxta.pipe.OutputPipeEvent;
import net.jxta.pipe.OutputPipeListener;
import net.jxta.pipe.PipeService;
import net.jxta.protocol.PipeAdvertisement;
import net.jxta.protocol.DiscoveryResponseMsg;
import net.jxta.discovery.DiscoveryListener;
import net.jxta.discovery.DiscoveryEvent;

public class PipeClient implements OutputPipeListener, DiscoveryListener{
static PeerGroup netPeerGroup = null;

private PipeService pipe;
private DiscoveryService discovery;
private PipeAdvertisement pipeAdv;

public static void main(String args[]) {
PipeClient myapp = new PipeClient();
myapp.startJxta();
}

private void startJxta() {
try {
netPeerGroup = PeerGroupFactory.newNetPeerGroup();
pipe = netPeerGroup.getPipeService();
discovery = netPeerGroup.getDiscoveryService();
System.out.println("The client joined the NetPeerGroup");
System.out.println ("Searhing for testPipeAdvertisement...");
discovery.getRemoteAdvertisements(null, DiscoveryService.ADV, "name", "testPipe", 1,null);
} catch (PeerGroupException e) {
System.out.println("fatal error : group creation failure");
System.exit(-1);
}
}

public void discoveryEvent(DiscoveryEvent ev){
try {
Enumeration ae = discovery.getLocalAdvertisements(DiscoveryService.ADV,"name","testPipe");
DiscoveryResponseMsg msg = ev.getResponse();
pipeAdv = (PipeAdvertisement) ae.nextElement();
System.out.println("...i've find it");
pipe.createOutputPipe(pipeAdv, this);
}
catch (Exception ex) {}
}

public void outputPipeEvent(OutputPipeEvent event) {
System.out.println("Got an output pipe event");
OutputPipe op = event.getOutputPipe();
Message msg = null;
try {
System.out.println("Creating message");
msg = new Message();
StringMessageElement sme1 = new StringMessageElement("Sending date",new Date(System.currentTimeMillis()).toString() , null);
StringMessageElement sme2 = new StringMessageElement("Greetings","Hello!", null);
msg.addMessageElement(null, sme1);
msg.addMessageElement(null, sme2);
op.send(msg);
} catch (IOException e) {
System.out.println("failed to send message");
System.exit(-1);
}
op.close();
System.out.println("message sent");
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
stheotok
Offline
Joined: 2007-03-12

PS. When you say "enable multicast" do you mean to simply check the "Multicast" box in
the platform configuration user interface, in the TCP settings? It's checked by default anyway, is that all that's required?

Thanks,
Steph.

tra
Offline
Joined: 2003-06-16

> PS. When you say "enable multicast" do you mean to
> simply check the "Multicast" box in
> the platform configuration user interface, in the TCP
> settings? It's checked by default anyway, is that all
> that's required?

Yes.

B.
>
> Thanks,
> Steph.

sowat
Offline
Joined: 2007-03-14

Hello my friend...

I am new in JXTA, and I was passing by the forum and find you "hello world" using pipe very interesting and useful for me... but like you I spend a very good time without having the pipe thing right...

Well, I found a solution I hope it fits you... the thing is that in your Rendevouz you probably have more than one pipeAdvertisement. How could that happen?? I don't know too... What I did was first I search form peers, then when I got the Rendesvouz adv, I used it to search for it's specific pipeadvertisement... and it worked!

hope I helped!

cheers

tra
Offline
Joined: 2003-06-16

> Hello my friend...
>
> I am new in JXTA, and I was passing by the forum and
> find you "hello world" using pipe very interesting
> and useful for me... but like you I spend a very good
> time without having the pipe thing right...
>
> Well, I found a solution I hope it fits you... the
> thing is that in your Rendevouz you probably have
> more than one pipeAdvertisement. How could that
> happen?? I don't know too... What I did was first I
> search form peers, then when I got the Rendesvouz
> adv, I used it to search for it's specific
> pipeadvertisement... and it worked!
You are correct. The problem is that the code is
creating a new pipe ID on every run.

pipeAdv.setPipeID(IDFactory.newPipeID(netPeerGroup.getPeerGroupID()));

This is creating different pipe advertisement on each run.

B.

>
> hope I helped!
>
> cheers

papelito
Offline
Joined: 2007-01-11

No, tra, it's still not workin'...
1)Multicast on jxta configurator is enabled
2)I've modified the client and server code, now the server registers itself like e rdvPeer and then publishes th pipeAdv, and the clients before calling the getRmoteAdv() method, searches for and connects to the rdvPeer.
3)I've glanced at jxta.org pipe tutorial, but in the example the pipe advertisement is not discovered, instead is builded through the same code, both by the client and th server.

Message was edited by: papelito

tra
Offline
Joined: 2003-06-16

> No, tra, it's still not workin'...
> 1)Multicast on jxta configurator is enabled
Ok.
> 2)I've modified the client and server code, now the
> server registers itself like e rdvPeer and then
> publishes th pipeAdv, and the clients before calling
> the getRmoteAdv() method, searches for and connects
> to the rdvPeer.
ok.
> 3)I've glanced at jxta.org pipe tutorial, but in the
> example the pipe advertisement is not discovered,
> instead is builded through the same code, both by the
> client and th server.
Are you using the latest release ?

B.

>
>
> Message was edited by: papelito

papelito
Offline
Joined: 2007-01-11

yes, version 2.4...
have you tried to run my code on your pc?

stheotok
Offline
Joined: 2007-03-12

Hello,

I am running into exactly the same problems you are describing here. I also tried running your code and observed the same things you do.

Have you managed to make any progress on this or solve it in the meantime?

Thanks,
Stephanos.

tra
Offline
Joined: 2003-06-16

> Hello,
>
> I am running into exactly the same problems you are
> describing here. I also tried running your code and
> observed the same things you do.
>
> Have you managed to make any progress on this or
> solve it in the meantime?
Either enable multicast or deploy a local rendezvous for
running your test.

B.
>
> Thanks,
> Stephanos.

stheotok
Offline
Joined: 2007-03-12

Thank you very much for your reply.

My problem seems to be is that I am not setting up the local RDV correctly. My client node gets the rdv service from the peer group:

rdvsvc = netPeerGroup.getRendezVousService();

but the check:

rdvsvc.isConnectedToRendezVous();

always returns false.

I am running a separate thread that implements the RendezVousListener, but I may not be doing it right (I'm a beginner with jxta).

Could you give me any pointers to instructions or examples for setting this up correclty?

Also one more question. I saw in some of the tutorial examples that the client node will simply wait to be connected to the RDV service, with a periodic check using isConnectedToRendezVous() as above. Is this enough, or should there be an explicit request for the node to connect to the RDV service. I am asking because I didn't see anything like that in the examples.

Thank you again,
Stephanos.

papelito
Offline
Joined: 2007-01-11

Thank for the replay tra, but i don't think you guess the problem...if in the same way i create and publish a group advertisement, the client peer is able to find that advertisement and can join the new group correctly...

tra
Offline
Joined: 2003-06-16

> Thank for the replay tra, but i don't think you guess
> the problem...if in the same way i create and publish
> a group advertisement, the client peer is able to
> find that advertisement and can join the new group
> correctly...
Currently your code does to register for a RendezVous
connect event and wait for the peer RDV connection to
occur before publishing the pipeadv. The only way the code can work is if you have multicast enable (adhoc mode).

You should check the pipe tutorial on jxta.org

Hth,

B.

tra
Offline
Joined: 2003-06-16

> I'm doing very simple examples with jxta, but
> neverthless i'm having some problems...
> In this example the client tries to search a pipe
> advertisement published by the server, but he doesn't
> find it. Can someone explain me why??
It is likely that you haven't enable multicast when
you configured the two peers.

Hth,

B.