The question about propagate pipe

朱國鼎 <[email protected]>
Newsgroups gmane.comp.java.jxta.user
Message-ID <001c01c5a592$698d3fc0$0301a8c0@0c1fa7c0520d423>
Hi,  
I have a problem with propagate pipe. I create a server, server is used to send message to multiple receiver. The following is my pipe advertisement. 

<?xml version="1.0" encoding="Big5"?>
<jxta:PipeAdvertisement>
 <Name>JXTACHAT</Name>
 <Id>urn:jxta:uuid-59616261646162614E504720503250338918BB40B3D94F00AB019C67D54254DB04</Id>
 <Type>JxtaPropagate</Type>
 <Description>JXTACHAT</Description>
</jxta:PipeAdvertisement>

The following is my server program (major part) : 

private void startJxta()
{
       group = PeerGroupFactory.newNetPeerGroup();

        groupAdvertisement = group.getPeerGroupAdvertisement();

        displayArea.append("getting Discovery Service…\n");
        discovery = group.getDiscoveryService();
        displayArea.append("getting Pipe Service…\n");
        pipes = group.getPipeService();
        startServer();
}
private void startServer()
{
        displayArea.append("starting service …\n");
        gid = group.getPeerGroupID();
        displayArea.append("read PropogateOut.adv…\n");
        PipeAdvertisement pipeadv = null;

        FileInputStream is = new FileInputStream("PropogateOut.adv");
                pipeadv = (PipeAdvertisement)
                          AdvertisementFactory.newAdvertisement(
                              new MimeMediaType("text/xml"), is);
                is.close();

        displayArea.append("publish pipe adv…\n");
        discovery.publish(pipeadv, DiscoveryService.ADV);
        discovery.remotePublish(pipeadv, DiscoveryService.ADV);

         displayArea.append("create Output pipe…\n");
        
        myOutputPipe = pipes.createOutputPipe(pipeadv, 30000);
        displayArea.append("pipe id is:" + pipeadv.getPipeID() +" \n");
        while(true)
        {
            msg = new Message();
            StringMessageElement sme = new StringMessageElement("DataTag", "Its for test", null);
            msg.addMessageElement(null, sme);
            myOutputPipe.send(msg);

            MessageElement msgElement = msg.getMessageElement(null, "DataTag"); 
 
           Thread.sleep(3000);
      }
  
 }

The following is my receiver program (major part) :

private void startJxta() 
{
    netPeerGroup = PeerGroupFactory.newNetPeerGroup();
    groupAdvertisement = netPeerGroup.getPeerGroupAdvertisement();
    displayArea.append("getting Discovery Service…\n");
    discovery = netPeerGroup.getDiscoveryService();
    displayArea.append("getting  Pipe Service…\n");
    pipes = netPeerGroup.getPipeService();
    startClient();
}

 private void startClient()
 {
        displayArea.append("finding Service adv.…\n");
        Enumeration en = null;
        while (true)
         {
            try {
                      displayArea.append("local searching …\n");
                en = discovery.getLocalAdvertisements(DiscoveryService.ADV 
                                                    , "Name"
                                                    , "JXTACHAT");

                    if ((en != null) && en.hasMoreElements()) {
                        break;
                    }

                  displayArea.append("remote searching …\n");
                discovery.getRemoteAdvertisements(null
                                              , DiscoveryService.ADV
                                              , "Name"
                                              , "JXTACHAT",1, null);
                        try { 
                                Thread.sleep(2000);
                        } catch (Exception e) {}

            }
            catch (IOException e) {}
        }

        displayArea.append("getting service advertisement!\n");

        try
         {
                PipeAdvertisement pipeadv2 = (PipeAdvertisement) en.nextElement();

                displayArea.append("create Input Pipe…" +pipeadv2.getPipeID()+ "…\n");
                myInputPipe = pipes.createInputPipe(pipeadv2, this); 

        } catch (Exception e) {
            e.printStackTrace();
            displayArea.append("Input Pipe fail");
        }
}
 //----------------------wait for message
public void pipeMsgEvent(PipeMsgEvent event)
{
        try
        {
            msg = event.getMessage();
            if(msg == null)
             {
                displayArea.append("msg is null…\n");
                return;
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
            return;
        }

        Message.ElementIterator en = msg.getMessageElements();
        if(!en.hasNext())
            return;
        MessageElement msgElement = msg.getMessageElement(null, "DataTag");
        if(msgElement.toString() == null)
            displayArea.append("message is null\n");
        else
            displayArea.append("the message is:" + msgElement.toString() + "\n");
 }

I don't know why my receiver cann't receive the message that server sended.  

Does anyone can tell me how to solve this problem ?

Thanks!
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.