Date post: | 31-May-2018 |
Category: |
Documents |
Upload: | talhakamran2006 |
View: | 217 times |
Download: | 0 times |
of 13
8/14/2019 jxmechat
1/13
Universal Chat Client for J2ME Enabled Mobile Devices Using
the JXME Implementation of JXTA
Troy EspirituAteneo de Manila University
265 Shoe Avenue Santo Nino
Marikina City Philippines
+6329427577
William YuAdviser
Ateneo de Manila University
ABSTRACT
Peer to Peer technology and mobile devices are two ideas that
have grown and expanded in the last few years; Peer to Peertechnology mostly because of file sharing and distributed
computing, while mobile devices for the always on the go. But
the two are not always synonymous with each other. Peer to
peer networks use large amounts of computing power, leaving
out most mobile devices. Mobile devices on the other hand, are
unstable with connections. In comes technology apt for the
generation, and one of them is JXME. JXME combines mobility
with connectivity, the ability to connect to a vast network of
peers on the Internet using your very own mobile device. Stay
connected, anywhere, anytime.
1.1 IntroductionIt is of no question that the most important asset a business or
even a normal person now possesses is information. It is the
Information Technology age when the transfer and
communication of information through various means is as
important as the money in the bank. If weve learned anything
over the past few years its the importance of pervasive, secure,
and reliable communications. Its not just about the Internet; its
also about communications inside and outside of your firewalls,
as well as mobile communications.[1]
Communication has been around since the dawn of man, but
never before has it been this important for the implementation of
pervasive and reliable transfer of information. Workspaces are
no longer limited to the office building; communication
problems no longer limited to the connection between the 4 th and
the 5th
floor. Business executives are always on the go and yet
need constant information sent to and from the main database in
the office. Managers should always be in contact with their
workforce whatever device they may be using, should it be a
PC, a mobile phone, a PDA; they are all connected. And with
the advancement of network technology these past years, the
ability to connect different networks across different platforms
has become a complex task. There have been many proposed
solutions, and one of them is JXTA. Juxtapose is a Sun
Microsystems technology that provides a solution to bridge the
communication gap between a PC and a mobile phone, a
technology that directly transfers information without need for
format conversion; JXME is JXTA for mobile devices.
1.1.1 Background
The Chat Client for Mobile Phones using JXTA protocol serves
as an example that peer to peer technology can now be handled
on limited mobile devices. The limitations of the hardware are
no longer an excuse not to include the mobile market in this new
network field. This is useful for it can show how different
devices can communicate with each other through different
platforms. With this study, it is hoped that the JXTA technology
can be clearly introduced to developers.
1.1.2 Motivation
Peer to peer technology is the wave of the future. No longer are
networks constrained on unreliable central servers, sharing and
connectivity is the focus. Decentralization of data and
communication adds security and reliability to an information
service.
Mobile communication has also been the trend lately. Corporate
as well as Consumer products are increasingly geared towards
mobility and interconnectivity. This is where our study focuses
on; the ability of mobile devices to easily interconnect with each
other.
1.1.3 Benefits
The main benefit of this work is perhaps the introduction of a
technology that will allow devices to connect to each other
1
8/14/2019 jxmechat
2/13
across different platforms and networks. The ability to connect
to each other without the need for the troublesome step of
configuring complex network access data on both sides will
surely help mobile users do more productive work instead of get
bogged down by connectivity problems. Juxtapose prides itself
in making connections across different platforms and different
networks, and we hope that it could also be done on mobilephones using JXME.
1.2 Review of Related Works
1.2.1 Related Works in JXTA
There are already a multitude of applications developed for the
peer to peer network that is JXTA. These applications range
from chat clients, distributed computing to file sharing. The two
applications discussed below are chat clients.
1.2.1.1 Myjxta [4]
Myjxta is an Instant Messenger that uses the Juxtaposeprotocols. The project is spearheaded by various members of the
JXTA project that can be found on the given website. This
project, aside from completely being peer to peer, combines a
lot of different services in one easy to install package. One on
one chat and Group Chat is available on this application.
Myjxta can run on Windows and Linux based Personal
Computers. Imagine Yahoo Messenger in its earlier stages,
focusing more on the communication aspect instead of aesthetic
enhancements.
It is not advisable to use though, for there are only very few
people using the application. Perhaps for development purposes,
Myjxta is a useful application, but for regular users, Myjxta just
is not widespread enough.
Myjxta also does not have the capability to operate on a mobile
phone. The application was not designed to be installed on a
mobile, and there is no client available for the mobile phone to
communicate with Myjxta.
1.2.1.2 JXTA Demo Chat Program [2]
Daniel Brookshier provides a great tutorial of using the JXTA
socket technology in Java. His tutorial uses a self made
application that can create peer to peer chat as long as one
knows the Login name of the user one wants to talk to. This
would perhaps be the basis of our work. His JXTA application
of pinpoint peer to peer chat is the essential reference we need to
do our thesis. We just need to see if we can implement it on
mobile phones as it cannot communicate with a mobile phone as
of yet.
There are lots of positive enhancements on this project. For one
thing, this project uses the new JXTA 2.0 Sockets to send and
receive data. It is patterned closely to the sockets we are familiar
with in Java. Another improvement is the automation of the
creation of unique IDs to be used in advertisements to allow the
network to discover newly connected resources. This will surely
allow dynamic linkage of network resources. Another positive
thing is that it supports multiple connections per applications. A
resource could be communicating with a certain resource whilesimultaneously receiving data from another.
It is incapable, though, of communicating with peers without the
specific ID given. Unlike other chat programs where the user
can dynamically find another user by searching, this application
needs the ID of the one to be communicated to upfront.
The most useful aspect of this project is the fact that it is a
tutorial, meaning we have the source codes and the explanations
behind it. This will be the starting point of our thesis as we are
still limiting ourselves to point to point chat on a network for
our mobile application.
1.2.2 Related Works in JXME
1.2.2.1 JXME Demo Chat Application
There are various demo applications within the package when
you download the JXME binary. The Chat demo contained
within the package contains a lot of the services provided for by
JXME. But the problem with the Chat Demo is that it is not
easily readable and comprehendible. A lot of the given functions
are also not working as stated. But the main problem is that the
application is too complex for basic beginner developers in
JXME. It is not a good way to start with JXME.
1.2.2.2 Various limited Demos and Tutorials on the
Internet
There are a handful of tutorials and demos on the Internet, but
most of them are really shallow and not that helpful. The most
useful was the demo by Michael Yuan that can be found on
http://www-128.ibm.com/developerworks/java/library/wi-
p2pmsg2/. It provides a simple easy to understand demo tutorial
that does not have the excess code that can mislead beginning
developers.
This tutorial helped in a way that it integrated the most basic
methods in JXME classes within a simple application.
1.3 Review of Related Technologies
Java will be the main language of choice in this project. To
implement on mobile devices, the Java Wireless toolkit will be
added onto Java 2 Standard Edition, using the Mobile
Information Device Profile 2.0. JXTA, JXME to be more
precise, will be used for the network aspect.
2
8/14/2019 jxmechat
3/13
1.3.1 J2ME Wireless Toolkit [5]
J2ME is not a stand-alone software development kit; it actually
needs J2SE as a base. It is a collection of technologies and
specifications designed for the different configurations of the
mobile device market. It is a collection because the mobile
market, and in essence, J2ME, encompasses a variety of devices,
there is no one size fits all solution. This means that a
developer only uses specific modules and configurations in the
progress of certain software. Software that might be destined to
run on low memory devices will be different from those that
require high memory; mobile devices are varied; and so
software should be designed with a specific configuration in
mind.
1.3.2 Mobile Information Device Profile [4]
MIDP 2.0 is an application environment for small wireless
devices that have intermittent network communication. MIDP is
not everything of J2ME, it is just the first to finish and be out in
the market. One can visualize MIDP as a version of the Java
Virtual Machine for mobile devices. It lets application designed
with MIDP specifications to run on mobile devices with said
runtime environment.
Here is a brief explanation of the J2ME-MIDP 2.0 technology
used in the development of the thesis.
javax.microedition.midlet
The MIDlet package defines Mobile Information
Device Profile applications and the interactions between the
application and the environment in which the application runs.
MIDlet A program that uses the MIDP API.
A MIDlet is a MID Profile application. The application must
extend this class to allow the application management software
to control the MIDlet and to be able to retrieve properties from
the application descriptor and notify and request state changes.
The methods of this class allow the application management
software to create, start, pause, and destroy a MIDlet. A MIDlet
is a set of classes designed to be run and controlled by the
application management software via this interface. The states
allow the application management software to manage theactivities of multiple MIDlets within a runtime environment. It
can select which MIDlets are active at a given time by starting
and pausing them individually. The application management
software maintains the state of the MIDlet and invokes methods
on the MIDlet to notify the MIDlet of change states. The MIDlet
implements these methods to update its internal activities and
resource usage as directed by the application management
software. The MIDlet can initiate some state changes itself and
notifies the application management software of those state
changes by invoking the appropriate methods.
javax.microedition.lcdui
The UI API provides a set of features for implementation of user
interfaces for MIDP applications.
Display This class is used to manage the various components
that are displayed on the screen at any given time. It is
responsible for what components are visible to the user
Display represents the manager of the display and input devices
of the system. It includes methods for retrieving properties of
the device and for requesting that objects be displayed on the
device. Other methods that deal with device attributes are
primarily used with Canvas objects and are thus defined there
instead of here.
There is exactly one instance of Display per MIDlet and theapplication can get a reference to that instance by calling the
getDisplay() method. The application may call the getDisplay()
method at any time during course of its execution. The Display
object returned by all calls to getDisplay() will remain the same
during this time.
A typical application will perform the following actions in
response to calls to its MIDlet methods:
startApp - the application is moving from the paused state to the
active state. Initialization of objects needed while the application
is active should be done. The application may call setCurrent()
for the first screen if that has not already been done. Note that
startApp() can be called several times if pauseApp() has been
called in between. This means that one-time initialization should
not take place here but instead should occur within the MIDlet's
constructor.
pauseApp - the application may pause its threads. Also, if it is
desirable to start with another screen when the application is re-
activated, the new screen should be set with setCurrent().
destroyApp - the application should free resources, terminate
threads, etc. The behavior of method calls on user interface
objects after destroyApp() has returned is undefined.
Form Graphical components such as Lists, TextFields, and
TextBoxes belong to a Form object that contains them.
A Form is a Screen that contains an arbitrary mixture of items:
images, read-only text fields, editable text fields, editable date
fields, gauges, choice groups, and custom items. In general, any
subclass of the Item class may be contained within a form. The
3
8/14/2019 jxmechat
4/13
implementation handles layout, traversal, and scrolling. The
entire contents of the Form scrolls together.
List A List gives the options available to the user.
A Screen containing list of choices. Most of its behavior is
common with class ChoiceGroup, and their common API. Thedifferent List types in particular, are defined in interface Choice.
When a List is present on the display, the user can interact with
it by selecting elements and possibly by traversing and scrolling
among them. Traversing and scrolling operations do not cause
application-visible events. The system notifies the application
only when a Command is invoked by notifying its
CommandListener. The List class also supports a select
command that may be invoked specially depending upon the
capabilities of the device.
The notion of a select operation on a List element is central to
the user's interaction with the List. On devices that have adedicated hardware "select" or "go" key, the select operation is
implemented with that key. Devices that do not have a dedicated
key must provide another means to do the select operation, for
example, using a soft key. The behavior of the select operation
within the different types of lists is described in the following
sections.
List objects may be created with Choice types of
Choice.EXCLUSIVE, Choice.MULTIPLE, and
Choice.IMPLICIT. The Choice type Choice.POPUP is not
allowed on List objects.
TextBox User text input.
The TextBox class is a Screen that allows the user to enter and
edit text.
TextField User text input.
A TextField is an editable text component that may be placed
into a Form. It can be given a piece of text that is used as the
initial value.
Command An event in a MIDlet.
The Command class is a construct that encapsulates the
semantic information of an action. The behavior that the
command activates is not encapsulated in this object. This
means that command contains only information about
"command" not the actual action that happens when command is
activated. The action is defined in a CommandListener
associated with the Displayable. Command objects are presented
in the user interface and the way they are presented may depend
on the semantic information contained within the command.
CommandListener The MIDlet listens for commands on the
Form, such as the selection of a choice in a List.
This interface is used by applications which need to receivehigh-level events from the implementation. An application will
provide an implementation of a CommandListener (typically by
using a nested class or an inner class) and will then provide the
instance to the addCommand method on a Displayable in order
to receive high-level events on that screen.
1.3.3 Juxtapose JXTA
The JXTA comprises an open network designed for peer to peer
computing. The basic idea is that each resource connected to a
network, such as a PC, a mobile device, a scanner, can be
designated as a peer, with a unique ID to identify it. These peers
connect to each other through the biggest Peer Group the NetPeer Group, which contains every peer using the JXTA
protocols.
Of course, its no use if we cannot limit our groups, but the
way JXTA does it, is by advertising and discovering. Peers and
Peer Groups can show that they are in the network by
advertising themselves. It is a way of uniquely identifying a
peer, a peer group, or a communication channel between peers.
JXTA provides a way of discovering these advertisements so
that peers may be able to find specific peers, group peers with
each other, and communicate between peers.
Peers use pipes to communicate and send messages to each
other. There are many types of pipes, but basically, they all do
the same thing, send messages. Messages, on the other hand, are
like special envelopes or casing for any data that a peer wants to
deliver to the other peer.
The great thing about JXTA is that it is platform and network
independent. It doesnt matter what your OS is, or what
networks you are using.
There are six sets of protocols that JXTA uses to connect peers,
peer groups and services together independent of their network
position, and with no need for a centralized server.
These are the six protocols and a short description follows:
Peer Resolver Protocol: A way of querying another peer and
receiving a response.
Peer Discovery Protocol: The mechanism that allows peers to
advertise themselves and their resources, and discover other
4
8/14/2019 jxmechat
5/13
peers and their respective resources. These peers use
Advertisements to describe themselves in the network so that
other peers can connect to them.
Peer Information Protocol: The mechanism by which a peer can
obtain status information about other peers.
Pipe Binding Protocol: Pipes are virtual communication
channels that are used to send and receive messages between
applications and peer services. This mechanism allows for the
creation and use of these Pipes.
Endpoint Routing Protocol: The mechanism used to connect a
peer to another if there is no direct route between each of them.
This can use other peers as middle-men to route the
information to the intended receiver. This protocol can find
alternate routes if the main route is lost.
Rendezvous Protocol: A propagation service allows peers tosend messages to multiple receivers. Within a peer group, peers
can either be rendezvous peers or peers that listen to rendezvous
peers. This protocol allows a peer to send messages to all
listening instances of the service. This is used by the PRP and
the PBP to propagate messages.
1.3.4 JXTA for Mobile Devices: JXME
The purpose of JXTA-J2ME is to provide JXTA compatible
functionalities on constrained devices using the Connected
Limited Device Configuration (CLDC) and the Mobile
Information Device Profile 2.0 (MIDP). The range of devices
includes the smart phones to PDAs. Using JXTA for J2ME, anyMIDP device will be able to participate in P2P activities with
other devices within the JXTA network. [jxme.jxta.org]
Figure 1 JXME Classes
The JXME API only has three classes, all in the net.jxta.j2me
package:
1. Element represents an element inside a JXTA
message. An element contains a name, a namespace, a
MIME type, and a binary array of data.
2. Message represents a JXTA message consisting of
several elements. Message provides methods to accessthose elements.
3. PeerNetwork is the most useful class. It specifies theJXTA tasks that a mobile peer can perform through
the relay. There are several useful methods in the
PeerNetwork class:
a. createInstance() is a factory method thatreturns an instance of PeerNetwork with a
specified peer name.
b. The connect() method connects to a relay ata specified HTTP URL. It returns a byte
array of persistent state information; this
information should be passed through the
connect() method in all subsequent
connections to the relay.
c. The create() method creates peers, groups,and pipes on the JXTA network through the
relay proxy.
5
8/14/2019 jxmechat
6/13
d. The search() method searches for peers,groups, and pipes.
e. The poll() method polls the relay formessages addressed to this mobile peer. It
can be called iteratively in a server thread.
f. The listen() and close() methods open andclose an input pipe respectively.
g. The send() method sends a message to aspecified pipe. [http://www-
128.ibm.com/developerworks/java/library/w
i-p2pmsg2/]
1.3.5 JXTA Relay (Support for JXME)
As JXME applications run on limited mobile devices and cannot
handle most of the requirements of a regular JXTA peer, JXME
uses the JXTA relay as a support to help it become a peer.
The JXTA relay can accept client commands and act upon the
commands on the client's behalf. The relay acts as a junction
between the JXTA network and peers (those that cannot directly
communicate with the JXTA network). A J2ME client uses
relays to share the XML authoring and processing burden.
JXTA has defined the data communication protocols that enable
messaging between a relay and a client. It is worthwhile to note
that a JXTA relay is not just meant to serve J2ME clients. A
relay can serve any client that can communicate according to the
specified protocols.
In any case, JXTA has provided a J2ME-based client-side
implementation that implements all communication with the
relay. It's called JXTA for J2ME, or JXME for short. Using
JXME with a relay lets J2ME clients act as JXTA peers.
The JXTA relay receives commands from a J2ME client,
perform what's necessary on the client's behalf, and represents a
JXME client on the JXTA network. The JXME client sends
commands and messages to the relay. The relay executes the
command on the JXTA network and returns the results back to
the JXME client. For example, Figure 3 shows the following
sequence of events: [6]
1. A JXME client sends a request to a relay to create a pipe.
2. The relay performs all the steps to create a JXTA pipe (for
example, authoring the pipe advertisement and sending the
advertisement to known rendezvous peers).
3. The relay returns the newly created pipe's identifier to the
JXME client.
Figure 2 Interaction Between Relay and Client
1.4 Objective
The objective of the thesis is to provide developers with an easy
and step by step process on how to develop JXME applications
through the development of a simple universal chat client with
presence service and messaging capabilities. Through these
simple applications, future developers can have an easy
understanding of how to build and run JXME enabled
applications.
1.5 Scope and Limitations
Due to the limited amount of time given, the application will not
deal with the extended JXTA network outside of the personal
JXTA relay server setup by the user. There will be presenceservice but only those using the same JXME chat application
developed in this thesis that is connected to the personally setup
JXME relay server.
Offline messaging is still out of scope, as well as conference
chat. Chat messaging will be limited to SMS type of interface, a
send and receive type, with no actual screen to store the
previous messages.
Testing will be limited to emulators run on the local system.
The scope of the thesis, though, provides a detailed process of
how to setup and build JXME applications that are not easily
found on Internet tutorials and demos. It starts from the basics
going up. The basic JXME methods are also discussed.
2.1 Project Description
The universal chat client provides users of J2ME-JXME enable
applications the ability to communicate with each other through
the JXTA relay server. Future designs will be able to sense the
6
8/14/2019 jxmechat
7/13
presence of other peers throughout the JXTA network, but for
our purposes, presence on the relay server is enough.
2.2 Architectural Design
2.2.1 Description of Components
The universal chat client has three key components with whichto build upon. A fourth one is also included, but it will not be
developed for it is the JXTA relay.
1. Graphical User Interface: a simple application
in J2ME to implement the JXME network
methods/protocols.
2. The Online Presence Service that allows the
application to know which peers are connected
to the relay server.
3. The Chat service that allows the user to send
messages between peers.
4. The JXTA Relay Server that allows the limited
mobile devices to run on the JXTA network.
2.3 Setting up of the Environment
Initially, the main project page of JXME, which is
http://jxme.jxta.org was the only primary source of information I
had on the thesis matter. I concentrated on making the various
demo programs given by the tutorials on the webpage.
Problem was that most of the tutorials lack step by step guides
on how to even setup the computer for JXME development.
Yes, there were working demos, but they had to use Ant to
build and compile the demo applications. And so, to better
understand the development of JXME, I decided to disregard
Ant and the recommended build xml files. I used trial and errorto learn how to compile and build JXME applications using only
the compiler in Java Wireless Toolkit.
2.3.1 Procurement and Deployment of Related Software
All of the needed software for development is easily obtainable
throughout the Internet. There are mainly four items to
download and install unto the system. Of course, it is understood
that the system of development is a Windows XP system
running on Intel Centrino technology. An optional text editor is
also recommended.
2.3.1.1 J2SE - J2METhe base developmental platform, J2SE can be obtained from
Suns Java website, http://java.sun.com. The additional APIs for
J2ME can also be downloaded from the same website.
Programmers knowledgeable of Java can easily install these two
development kits. It is recommended that all these are installed
in a directory with no spaces.
Development of the thesis used Java 2 SE 1.5.0_6 and Java
Wireless Toolkit 2.2. Development in the toolkit is unique, as
one can only create folders within the \WTK22\apps directory,
as j2me requires specific folders and files that are automatically
generated by the toolkit. (Ktoolbar application)
2.3.1.2 JXMEThe JXME source code, jar file and demo programs can be
easily obtained from JXTAs JXME project page at
http://jxme.jxta.org (go to the documents and files page). In this
research, the stable 2.1.1 version of JXME was used. Unzip the
file in the same folder as the earlier two.
The zip file containing all these JXME files is complex to
understand, but for the purposes of the just building an
application, all we need to do is to get the jxta-cldc.jar file from
one of the demo folders lib folder (for example C:\jxme-
2.1.1\midp\demo\chat\lib) and transfer it to the lib folder of the
project you created in the ktoolbar application of the wirelesstoolkit.
Figure 3: The JXME jar File
2.3.1.3 JXTA Relay
There are many ways to run a JXTA relay. But from experience,
the easiest way is to download the JXTA shell (binary, and for
the development of this application, JXTA shell 2.3.6 was used)
from the download page of http://www.jxta.org. Unzip the file
into the same directory of the previous three.
To run the relay, go to the \jxta-shell-2.3.6\shell folder and click
on the run.bat file and it will start the JXTA shell for you. This
shell, once running also acts as a JXTA relay if configured to do
so.
7
8/14/2019 jxmechat
8/13
Figure 4: The Shell Folder
If it is the first time the shell runs, it will ask for some
configurations. Pictures below show how one should configure
the shell to act as a relay for the JXME application to be
developed. (If one wants to reconfigure the shell, one can delete
the .jxta folder to delete the saved configurations.)
Figure 5: Shell Configuration 1
Figure 6: Shell Configuration 2
Figure 7: Shell Configuration 3
For the purposes of this application, follow configuration as
above.
8
8/14/2019 jxmechat
9/13
Figure 8: The Shell
The JXTA shell acting as a relay for JXME applications.
2.3.1.4 Crimson Editor
Crimson editor is a versatile text editing program thatrecognizes a lot of programming language syntax. Since we will
be using the wireless toolkit to build and package the
application, IDEs like jcreator and gel are not advisable. It can
be found at http://www.crimsoneditor.com.
2.4 Development of the System
2.4.1 The Graphical User Interface
The GUI is made up of 3 basic screens, the configuration, online
presence and chat screens. The configuration screen lets the user
setup the variables that will help the application setup and
connect to the JXTA relay and JXTA network. The online
presence screen allows the application to know which peers are
connected to the relay server. And the chat screen allows the
user to input a message to be sent to another peer.
Figure 9: The GUI Screens
2.4.2 Explanation of the Code
9
8/14/2019 jxmechat
10/13
Of course, in the development of the system, the GUI must be
first developed so that there will be a skeleton to the system. As
previously stated, J2ME was used and 3 screens were written.
The 4 main components of a J2ME application are required.
Some classes were also imported, especially the 3 JXME classes
needed to run on the JXTA network.
After setting up the GUI, the next part was to connect to the
relay server and eventually to the JXTA network. This is done
through the createInstance() and .connect() methods. A special
propagate pipe was created so that the application can tell All
the peers connected to the relay that it was online. A special
unicast pipe is also created for the ability of this peer to receive
messages from other peers.
There are two types of messages that we are sending through the
network. One is an Im alive message sent through this
propagate pipe and received by all peers, and a P2P message
sent only to another peer through a unicast pipe. These are 2
methods that create the two messages.
public class MainChat extends MIDlet implements
CommandListener, Runnable{
public MainChat()
{
setupConfigScreen();
setupSendScreen();
showOnlineSetup();
}
public void startApp()
{
display = Display.getDisplay(this);
display.setCurrent(configForm);
}
public void destroyApp(boolean unconditional)
{}
public void pauseApp()
{
}
public void setupConfigScreen()
{
configForm = new Form("Configuration");
peerNameTF = new TextField("Peer Name:
", "anonymous", 256, TextField.ANY);
title = new StringItem("Mobile JXME Chat",
null, Item.PLAIN);
subTitle = new StringItem("Enter
Configuration Details", null, Item.PLAIN);
configForm.append(title);
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.io.*;
import java.util.*;
import net.jxta.j2me.PeerNetwork;
import net.jxta.j2me.Message;
private String propaPipeID = "urn:jxta:uuid-" +
"59616261646162614E50472050325033" +
//"D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D104";
"D1D1D1D1D1D141D191D191D1D1D1D1D104";
public void connect()
{
try
{
peer =
PeerNetwork.createInstance(peerName);
persistentState = peer.connect("http://" +
relayHost + ":" + relayPort, null);
// create propa pipe
messageID = peer.create(PeerNetwork.PIPE,
"PropaPipe", propaPipeID, "JxtaPropagate" );
peer.listen(propaPipeID);
}
10
public void run()
while(true)
{
myPipeID = createPipe(peerName);
public String createPipe(String pipeName)
{
String pipeId = null;
try
{
int messageID =
peer.create(PeerNetwork.PIPE, pipeName, null,
PeerNetwork.UNICAST_PIPE);
Message msg = peer.poll(5000);
pipeId = processMessage(msg, messageID,
8/14/2019 jxmechat
11/13
The message sent through the network contains an element class
that hold various information that the developer wants to send
to the other peer. The first message just contains the name of the
peer and its unicast pipe ID so that other peers may reply to it.
The second message contains an Element class that holds thename, the pipe ID and the message itself written on the Chat
screen.
For the application to know whether it has messages waiting on
the relay server, the application polls the server. This is also
done to know who else are running on the relay server. This
polling is run through a thread and is iterated. The messages
received are then processed and dealt with accordingly. Note
there are 2 polls, the user created and the poll method of the
JXME class.
Vectors keep track of which peers are currently online, and
when an update comes, the vectors inform the choice group ofwhich peers are still online, and which are not.
2.5 Difficulties
public void run()
{
while(connected && poll())
{
//send out im alive messages refresh vector
list of buddies.
}
}
private boolean poll()
{
Message msg = null;
try
{
msg = peer.poll(1000);
}
try
{
for(int j=0; j < msg.getElementCount(); j++)
{
Element e = msg.getElement(j);
System.out.println(j + ": " + e.getName() + " = "
+ new String(e.getData()));
if(e.getName().equals("ALIVE"))
{
buddyName = new
String(e.getData());
11
public Message createImAliveMessage(String pName, String
myPipeID)
{
Element[] elements = new Element[2];
elements[0] = new Element("ALIVE", pName.getBytes(), null,
null);
elements[1] = new Element("myPipeID",
myPipeID.getBytes(), null, null);
Message message = new Message (elements);
return message;
}
public Message createP2PMessage(String pName, String
myPipeID, String msgText)
{
Element[] elements = new Element[3];
elements[0] = new Element("P2P", pName.getBytes(), null,null);
elements[1] = new Element("myPipeID",
myPipeID.getBytes(), null, null);
elements[2] = new Element("P2PMessage",
msgText.getBytes(), null, null);
long time = System.currentTimeMillis();
if (time - lastPropa > 5000)
{
lastPropa = time;
Message imAlive = createImAliveMessage(peerName,
myPipeID);
messageID = peer.send(propaPipeID, imAlive);
for(int i = buddyListTimes.size() - 1; i >= 0; i-- )
{
if((time -
(((Long)buddyListTimes.elementAt(i)).longValue())) > 6000)
{
int itemNum =
((Integer)buddyListItemNumber.elementAt(i)).intValue();
// onlineForm.delete(itemNum);
buddyChoiceGroup.delete(itemNum);
buddyListItemNumber.removeElementAt(i);
buddyListNames.removeElementAt(i);
v
8/14/2019 jxmechat
12/13
During the course of the research, many difficulties hampered
the development of the system. The main site at jxme.jxta.org
contained information about JXME, but it was not for beginners.
Being the main project site, jxme.jxta.org is insufficient for the
study. If only this site was properly maintained and contained
much more, it would have been easier.
2.5.1 Research
There were a handful of demos and tutorials on the Internet
about JXME, but problem was that most of it is old and assumes
that the developers already know much about the topic. They cut
corners a lot of necessary things and steps making life for the
beginner developer hard. It was not until I found a detailed IBM
website on JXME that progress ensued.
2.5.2 Environment
The main tutorial package of JXME was the one included in the
downloadable binary file at the main JXME project page. The
problem with this tutorial was that it automated everything from
the compilation, packaging and building. For a beginner, this did
not help for the reason that I cannot compile short and simple
codes to test out. I had to use trial and error and relearn J2ME
just so I can compile from scratch.
2.5.3 JXME
JXME lacks the necessary support of developers. Tutorials and
Demos are dated and far in between. One really needs to look
hard if one wants to learn; coupled with the fact that the current
JXME 2.0 has a different API from the previous ones, so most
of the demos and tutorials done previously are incompatible to
the current one.
3.1 RESULTS AND DISCUSSION
Implementation of the basic classes and methods of JXME on a
mobile device has been a success. Presence service is
operational, although limited only to those peers using the same
application and running on the same relay server. Chatting was
made simpler by just alerting the user if a message has been
received. Point to point chat is operational and is functioning
well.
4.1 CONCLUSION AND
RECOMMENDATIONS
Peer to peer technology, including JXTA and its mobile
counterpart, JXME, have a very big potential in changing the
way we do things. This thesis, simple as it may be, has shown
the power of JXME in creating connections between peers. If
developed correctly and extensively, a lot more uses for the
technology can be found.
Some Recommendations for further development:
1. The ability to chat with multiple persons at a time.
2. The ability to share files between mobile devices.
3. The potential to communicate with a vast array of
devices and not just the mobile phone.
4. The ability to search for and communicate with peers
using a different application client.5. If possible, use JXME to voice communicate over the
network.
5.1 ACKNOWLEDGEMENTS
I would like to thank Mr. William Emmanuel S. Yu of the
Department of Information Systems and Computer Science for
providing me with the necessary direction and assistance to
fulfill this requirement. Gratitude is also due Ms. Ma. Mercedes
T. Rodrigo, Ph. D., Chair of the Department of Information
Systems and Computer Science for the support she has given
me. I would not have finished my thesis without these two
teachers understanding where I am clearly deficient. I wouldlike to thank my batch mates especially Cecilia, Esmee, Mark,
Andree, Lloyd, Joboy, and Arbi for the support and
encouragement. They pointed me in the right direction,
especially in the fields of J2ME, research, testing and
debugging.
6.1 REFERENCES
[1] Andriole, S., Pervasive Communications, Datamation
EarthWeb Website,
http://itmanagement.earthweb.com/columns/bizalign/article.php/
757621.
[2] Brookshier, D., The Socket API in JXTA 2.0, Sun
Developer Network,
http://java.sun.com/developer/technicalArticles/Networking/jxta
2.0/.
[3] Mobile Information Device Profile, Sun Developer
Network J2ME, http://java.sun.com/products/midp/index.jsp.
12
8/14/2019 jxmechat
13/13
[4] MyJXTA Project Home, JXTA, http://myjxta.jxta.org/.
[5] Sun Java Wireless Toolkit, Sun Developer Network,
http://java.sun.com/products/sjwtoolkit/.
[6] Yuan, Michael, Mobile P2P Messaging, IBM Website,http://www-128.ibm.com/developerworks/java/library/wi-
p2pmsg2/
13