Re: [Beepcore-java-users] Peer-to-peer message exchange
Status: Beta
Brought to you by:
huston
|
From: William J. M. <wm...@es...> - 2006-10-03 18:11:25
|
That channel you opened is peer to peer, you should be able to send a
MSG from A to B in there just fine. Either side can send messages in a
channel as long as the profile supports it.
-bill
On Tue, Oct 03, 2006 at 01:39:58PM -0400, eri...@be... wrote:
> Hi
>
>
>
> I have the following scenario:
>
>
>
> Server A listening on port 1234
>
> Server B initiating a session on server A using BEEP
>
> Server B start a channel
>
> Server B sends a MSG and got a reply from server A.
>
>
>
> I want at this point that the server A sends a MSG to server B. But
> server A can't send messages since it doesn't know which channel to use.
> Also, Server B is not listening at all. How could I tell the Server B to
> listen for MSG and tell server A which channel to use? Do I need to
> create a new TCPSession.listen(port+1, profileRegistry) on server B and
> on server A initiates a connection to the server B ???
>
>
>
> Here's the source code for server A:
>
>
>
> ProfileRegistry = new ProfileRegistry();
>
> mFlapProfile = new FlapProfile();
>
>
>
> // Initialize the profile and add it to the advertised profiles
>
> ProfileRegistry.addStartChannelListener("http://sitacs.uow.edu.au/ns/loc
> ation/flap/beep",
>
>
> mFlapProfile.init("http://sitacs.uow.edu.au/ns/location/flap/beep",
> null),
>
> null);
>
>
>
> public void run() {
>
> try {
>
> // Loop listening for new Sessions
>
> while (true) {
>
> TCPSessionCreator.listen(port, ProfileRegistry);
>
> } catch (Exception e) {
>
> log.error("Listener exiting", e);
>
> }
>
> }
>
>
>
> Here's the source code for server B
>
> public synchronized void run() {
>
> //Initiate a session with the server
>
> try {
>
>
>
> mSession = TCPSessionCreator.initiate(host, port);
>
> mChannel = mSession.startChannel(FlapProfile.URI);
>
> //send first MSG and got reply in this method
>
> initiateSync ();
>
> mChannel.setRequestHandler(this);
>
>
>
> while (mSession.getSocket().isConnected()) {
>
> //wait for incoming data what to do here ????
>
> }
>
>
>
> } catch (BEEPError e) {
>
> if (e.getCode() == 550) {
>
> System.err.println("bing: Error host does not support " +
>
> "echo profile");
>
> } else {
>
> System.err.println("bing: Error starting channel (" +
>
> e.getCode() + ": " +
>
> e.getMessage() + ")");
>
> }
>
> return;
>
> } catch (BEEPException e) {
>
> System.err.println("bing: Error starting channel (" +
>
> e.getMessage() + ")");
>
> return;
>
> } catch (InterruptedException e) {
>
> // TODO Auto-generated catch block
>
> e.printStackTrace();
>
> }
>
> }
>
>
>
> private void initiateSync() {
>
>
>
> Reply reply = new Reply();
>
> InputStream is = null;
>
>
>
> String lSync = "<?xml version='1.0' encoding='UTF-8'?>" +
>
> "<sync xsi:type='sync' xmlns='urn:flap'/>";
>
>
>
> try {
>
> // Send the synchronization request
>
> mChannel.sendMSG(new StringOutputDataStream("application/xml",
> lSync),
>
> reply);
>
>
>
> while (reply.hasNext()) {
>
> //Get the reply to the request
>
> is = reply.getNextReply().getDataStream().getInputStream();
>
>
>
> Document lDoc = mDomBuilder.parse(is);
>
> //Convert the XML request to a Java object
>
> Unmarshaller lUnmarshaller =
> mJaxBContext.createUnmarshaller();
>
> JAXBElement instance =
> (JAXBElement)lUnmarshaller.unmarshal(lDoc);
>
> SyncrType lSyncResponse = (SyncrType)instance.getValue();
>
>
>
> //TODO Save information
>
> System.out.println("Save information");
>
> }
>
> } catch (SAXException e) {
>
> // TODO Auto-generated catch block
>
> e.printStackTrace();
>
> } catch (JAXBException e) {
>
> // TODO Auto-generated catch block
>
> e.printStackTrace();
>
> } catch (BEEPInterruptedException e) {
>
> System.err.println("bing: Error receiving reply (" +
>
> e.getMessage() + ")");
>
> e.printStackTrace();
>
> } catch (BEEPException e) {
>
> System.err.println("bing: Error sending request (" +
>
> e.getMessage() + ")");
>
> e.printStackTrace();
>
> } catch (IOException e) {
>
> System.err.println("bing: Error receiving reply (" +
>
> e.getMessage() + ")");
>
> e.printStackTrace();
>
> }
>
> }
>
>
>
> Regards,
>
> Eric
>
>
>
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Beepcore-java-users mailing list
> Bee...@li...
> https://lists.sourceforge.net/lists/listinfo/beepcore-java-users
|