Skip to main content

How can I send a message from a JXME peer to a JXTA peer ?

3 replies [Last post]
iulianp26
Offline
Joined: 2007-04-22

Hi,

I've managed to send messages from a JXTA peer to a JXME peer using the JXTA shell as relay & rendezvous. For this I had configured the JXTA peer to use the shell as rendezvous seed peer (http://127.0.0.1:9700)

But I haven't succeeded in communicating in the opposite way (from JXME peer to JXTA peer).

All peers run on the localhost (JXME and JXTA peers, JXTA shell).

Here are some notes about the way I've tried it:

JXME peer:
.......................
peer.create(PeerNetwork.PIPE, pipeName, pipeId, pipeType);
........................
peer.listen(pipeId);
........................
peer.send(pipeId, msg);

JXTA peer:
...................
pipeIn = pipe.createInputPipe(pipeAdv, this); // pipeAdv has the same pipeId as of created JXME pipe
...................
public void pipeMsgEvent(PipeMsgEvent event) {
Message msg=null;
try {
msg = event.getMessage();
...............
}

The configuration of the JXTA shell was:
- act as a relay, rendezvous and JXME proxy
- TCP enabled, multicast, incoming/outgoing connections enabled; port 9701
- HTTP enabled, incoming/outgoing connections enabled; port 9700

I've tried many configurations for the JXTA peer but it didn't work.

Please give me some advices.
Thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
asghar
Offline
Joined: 2005-07-26

Hi

It was for me a question, which protocol uses your JXME-driven peer to access the jxta network?
Still no time to start the learning of JXME. However I’m familiar with Java ME.

In order to become familiar with JXTA technology, I’m currently studying JXTA for Java Standard Edition (I named it simply [b]JXSE[/b]).
I think like JXME, [b]JXSE [/b] is a sounding name too. Isn’t?

I try to give you some tips and hope they are correct.

[b]1.-[/b]
JXTA is a networking and programming platform for P2P computing & communications. And this independently of:
• Underlying „OSs“, of peers, involved in a jxta-network and
• Transport - protocols, used by peers to establish or join a given jxta-peer group (network).
TCP is the most used protocol, whereby individual peers may use other transport protocols (i.e. RFCOMM or L2CAP of Bluetooth – protocol stack) to access the jxta – network, run by TCP / IP.

[b]2.-[/b]
Two devices, driven by (any version of) JXTA platform ([b]JXSE[/b], JXME, C, C++,…) become able to communicate, when they belong to the same peer group or belonging to different groups, interconnected via relay(s). (Assumed, they are authorized to communicate.)
In your case, the peers belong to the same peer group AND all residing on your local subnet. … so you don’t need to use a relay!

[b]In addition:[/b] JXTA shell is a jxta - application and NOT a peer!
As far as I know, it’s available only for JXSE.
It’s used to configure the environment of JXTA platform.
I don’t know, what “[b]JXME Proxy[/b]” is or does?
It seems to be an important setting but on the jxta.org I didn’t find something about it.

[b]3.-[/b]
stated roughly, Jxta peers communicate to provide or consume 2 kind of services:

[b]Platform Services:[/b] which are available to peers by implementation of 6 JXTA protocols.
This may also include services, provided by 3. parties, aimed to extend the platform’s core services, which are specified by JXTA Protocol Specification V 2.0.
Advertisements are used to create and publish such types of services.

[b]Custom Services[/b]: they are represented by the code of application developers.
Pipe are used to consume such services. I think for almost real life applications, a more reliable transport protocol (i.e. TCP, the related API is located in net.jxta.socket – package or
util.JxtaBiDiPipe / util.JXtaServerPipe) is needed than UDP, which is used by simple pipe and all core platform’s services.

You are using pipe and I guess, there you make some mistake.
At this stage, it’s maybe better, that you keep yourApp simple. For that you can drop the use of pipe and instead do something simple. For example query your JXSE-driven Rendezvous peer to deliver the name of all peers of your peer group and check if the JXME-driven peer is also there.

[b]4.-[/b]
Read carefully the JXTA Programmer’s Guide. It exposes the consistency and reliability, established by the Java community’s literature.
The available version is 2.3.x. The included samples are to be slightly updated (use of JXTA 2.4.1 API).

[b]5.-[/b]
Pay attention to set TCP / IP configuration – parameters of native system, on it’s top JXME or JXSE is running.

Asghar

iulianp26
Offline
Joined: 2007-04-22

Hi Asghar,

The application which I want to develop using the JXTA technology is an instant messaging application for mobile phones. Communication between two mobiles is performed via a relay (I must have this for mobiles) and using pipes (there is the chat demo application for JXME which I used as an example).

In addition, I want to have a server (a normal JXTA peer running on the same machine as the shell relay) which I want to use it to access a database storing users, offline messages, etc. Messages will be sent in three ways as follows, the relay being used for all:
1. JXME peer (mobile) -> JXME peer (mobile)
2. server (JXTA peer) -> JXME peer (mobile)
3. JXME peer (mobile) -> server (JXTA peer)

Now, I've managed to implement the first two but I have problems with sending a message from a JXME peer to the server. I suspect that I'm not making the proper configurations for the JXTA peer.

Iulian

asghar
Offline
Joined: 2005-07-26

Hi Lulian!

As mentioned before, currently I don’t know too much about JXME, however I think (like the existing relationship between Java SE & Java ME) JXME must be a subset of JXSE, while some parts are modified to meet the requirements of embedded systems.
I took a look at APIs of JXME and saw that currently JXME doesn’t support the BiDiPipe and the package socket is unfortunately completely missing, even Java ME supports socket.

Here some questions to the community (please answer):

a. Is there any current work to support socket for JXME?

b. Is there any current work to support BiDiPipe for JXME?

c. Can somebody give me a link, to read some sentences about [b]JXME Proxy[/b] setting, included in the JXTA platform configuration?

[b] I - JXSE sends message to JXME[/b]

JXME peer = hosting JXTA platform for Java ME
JXSE peer = hosting JXTA platform for Java SE

[b]1.-[/b]
Within the peer group, each peer creates the default NetPeerGroup and obtains it’s pipe service:
pipeService = netPeerGroup.getPipeService();

A pipe is an unsecured, unreliable, UNIDIRECTIONAL, asynchronous message delivery mechanism. It has 2 ends: the input & the output. (In the API of Platform they are referred as InputPipe and OutputPipe! When I see them, I think of: Pipe´sInput, Pipe´sOutput.

[b]2.-[/b]
Then EACH peer (JXSE & JXME) creates a PipeAdvertisment by call to related API of AdvertismentFactory and use of a XML - document, which describes this pipe. (for complex apps, it’s recommended to put such methods in a helper - class)

[b]3.-[/b]
JXSE peer must have an OutputPipe to send message to the other end of the pipe. You create it by call to pipe.PipeService API, perhaps as following:
createOutputPipe(PipeAdvertisement pipeAdv, OutputPipeListener listener)

The Java class, representing the JXSE peer must implement the OutputPipeListener, in order to become able to send message to the other end of the pipe.
In your event-handler (OutputPipeListener.outputPipeEvent(OutputPipeEvent event)) you create the message, which is to be sent.
EACH TIME yourApp (JXSE peer) creates an OutputPipe, the jxta platform knows, there is a new message there, which must be sent to the other end of the pipe. To do it, the platform calls your event handler!

[b]4.-[/b]
JXME peer must have an InputPipe to receive message from the other end of the pipe. You create it by call to pipe.PipeService API, perhaps as following:
createInputPipe(PipeAdvertisement pipeAdv, PipeMsgListener listener)

The Java class, representing the JXME peer must also implement the PipeMsgListener, in order to become aware, when a message arrives and then process it within it’s event handler (i.e. display the content of the message).

[b] II- JXME sends message to JXSE[/b]

NOTE: pipe is an UNIDIRECTIONAL message delivery mechanism!
This means, the message follows from sender to receiver ONLY!
It means, the procedure mentioned above must be implemented once again, if ALSO JXME peer must become able to send message to JXSE peer, … BUT this time the role of peers are to be exchanged! This means:

• The (Java class, representing) JXME peer must implement OutputPipeListener & create the OutputPipe now (to become sender)

And

• The (Java class, representing) JXSE peer must implement PipeMsgListener & create the InputPipe now (to become receiver)!

• The step 1 and 2 must not be repeated, because (for both ends of the pipe) pipeService and pipeAdv are already there and can be reused.

I hope these are all correct.

Asghar