Thread: [Beepcore-java-users] Peer-to-peer message exchange
Status: Beta
Brought to you by:
huston
|
From: <eri...@be...> - 2006-10-03 17:40:10
|
Hi
=20
I have the following scenario:
=20
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.
=20
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 ???
=20
Here's the source code for server A:
=20
ProfileRegistry =3D new ProfileRegistry();
mFlapProfile =3D new FlapProfile();
=20
// Initialize the profile and add it to the advertised profiles
ProfileRegistry.addStartChannelListener("http://sitacs.uow.edu.au/ns/loc
ation/flap/beep",
=20
mFlapProfile.init("http://sitacs.uow.edu.au/ns/location/flap/beep",
null),
null);
=20
public void run() {
try {
// Loop listening for new Sessions
while (true) {
TCPSessionCreator.listen(port, ProfileRegistry);
} catch (Exception e) {
log.error("Listener exiting", e);
}
}
=20
Here's the source code for server B
public synchronized void run() {
//Initiate a session with the server
try {
=20
mSession =3D TCPSessionCreator.initiate(host, port);
mChannel =3D mSession.startChannel(FlapProfile.URI);
//send first MSG and got reply in this method
initiateSync ();
mChannel.setRequestHandler(this);
=20
while (mSession.getSocket().isConnected()) {
//wait for incoming data what to do here ????
}
=20
} catch (BEEPError e) {
if (e.getCode() =3D=3D 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();
}=20
}
=20
private void initiateSync() {
=20
Reply reply =3D new Reply();
InputStream is =3D null;
=20
String lSync =3D "<?xml version=3D'1.0' encoding=3D'UTF-8'?>" +
"<sync xsi:type=3D'sync' xmlns=3D'urn:flap'/>";
=20
try {
// Send the synchronization request
mChannel.sendMSG(new StringOutputDataStream("application/xml",
lSync),
reply);
=20
while (reply.hasNext()) {
//Get the reply to the request
is =3D reply.getNextReply().getDataStream().getInputStream();
=20
Document lDoc =3D mDomBuilder.parse(is);
//Convert the XML request to a Java object
Unmarshaller lUnmarshaller =3D
mJaxBContext.createUnmarshaller();
JAXBElement instance =3D
(JAXBElement)lUnmarshaller.unmarshal(lDoc);
SyncrType lSyncResponse =3D (SyncrType)instance.getValue();
=20
//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();
}
} =20
=20
Regards,
Eric
=20
=20
|
|
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
|