Transcript Java ME

Getting Started with JXTA
for J2ME
Advisor : Dr. Ching-Long Yeh
Report : DI.2, 洪泰昌 (89506005)
Course: XML文件管理
Abstract

Ad hoc networks : a self-configuring network of
mobile





Self-organization ability: simplify management,
robustness, flexible
Well suited to the vicissitudes of wireless
P2P model enables “mobile devices” to assemble
quickly
JXTA ("juxtapose") , a set of protocols for P2P
networking
In this report:


How the JXTA protocols are extended to MIDP
How to install and run JXTA demonstration programs
for MIDP
Abstract

JXTA demonstration programs for MIDP

Chat MIDlet
JXME Proxy
(Relay)
DEMO
Agenda






Abstract
JXTA
Java ME (J2ME)
JXME
Summary
Appendix




Prerequisite for implementation
Implementation of J2ME Chat MIDlet
Implementation of JXME Proxy
References and Resources
JXTA

JXTA defines a set of open protocols for
peer-to-peer networks



JXTA (v2.0) Protocol Specification
XML-based protocols
Functionalities





peer discovery
endpoint routing
connection binding
basic query/response message exchange
network propagation through rendezvous peers
Java ME

Java ME:

Java Platform, Micro Edition (Java ME) provides a
environment for applications running on mobile and
other embedded devices


mobile phones, personal digital assistants (PDAs), TV settop boxes, and printers
MIDP: Mobile Information Device Profile (v2.0)


Implementation Specification
Subset of Java SE (JDK)  limited capacity
Java ME

MIDP:






javax.microedition.rms
 Record Management System, persistence
javax.microedition.midlet
 Environment, lifecycle
javax.microedition.io
 Network
javax.microedition.lcdui
 UI(User Interface)
Java.lang.* java.util.*
MIDlet : application

javax.microedition.midlet.MIDlet
Java ME

MIDlet:

Managed by Application Management software
(AMS) : Paused,Active,destroyed
JXME


JXME :
 JXTA Java Micro Edition (MIDP/CLDC/CDC)
Project
The goal of the JXME project is to bring JXTA
functionality to MIDP devices


Why JXME ?  The constraints of Mobile Device




A framework
XML parser  memory limits of MIDP devices?
The state of the network  needs to be cached  memory
limits of MIDP devices?
MIDP mandates support for HTTP, but socket and
datagram connections are optional
JXTA protocols exceed the minimum requirements
of MIDP  JXTA relay
JXME Architecture
Rendezvous/relays
Coordination between J2ME Edge
Devices and JXTA Relays
1.
2.
3.
4.
J2ME peer send HTTP request messages to a JXTA relay
JXTA relay parse each name-value pair in the HTTP request
XML messages (JXTA format)  relay the messages over the
JXTA network
JXTA relay receives a message from the JXTA network parse the
XML format of the incoming message  author a corresponding
HTTP response
Wait for the J2ME peer to send an HTTP poll request  send the
HTTP response back to the J2ME peer
1.
2.
Response
4.
3.
JXME API



Element: elements of JXTA Message
Message: JXTA Message, access methods
PeerNetwork:







createInstance(): create PeerNetwork instance
connect(): connect to relay
create(): peer, group, pipe
search(): peer, group, pipe
poll() poll the information from relay server
listen() and close(): open and close pipe
send(): send the message to the pipe
JXME Code Example

Create pipe
Create
peer
Connect
to proxy
create
pipe
JXME Code Example

Find the pipe which we created
JXME Code Example

Send message through the pipe which we just find
JXME Code Example

Receive message
Summary



JXTA furnishes an XML-based, platformindependent set of protocols that enable P2P
networking
JXME project brings JXTA functionality into
the MIDP world
Vision: Ad hoc network  Every mobile
device as “Server”
Summary

Not popular ? Why ?



In the future




Cost: GPRS, 3G …?
Mobile device: Power consumption, UI ?
WiMax  cost down
Wireless  Leased-line network  connected
anytime
Google Android platform ?  XMPP protocol
Trends: P2P network + XML based
protocol
Appendix
Prerequisite for implementation

Required libraries from
http://download.java.net/jxta/

jxse-lib-2.5.zip



jxme-2.1.3-bin.zip



JXTA core
JMEX Proxy libraries
JXME framework
Chat MIDlet code and libraries
Tools:


NetBeans (6.0) + Mobility pack
http://www.netbeans.org/
Implementation of J2ME Chat
1. New project Mobile  mobile project from existing MIDP source
MIDlet
Implementation of J2ME Chat
2. Specify the source and JAD file
MIDlet
Implementation of J2ME Chat
3. MIDlet
Name and Location  name  chat
Implementation of J2ME Chat
4. MIDlet
Default Platform Selection : use default
Implementation of J2ME Chat
5. MIDlet
Add library : chat porject  right click  properties  add Jar/Zip  jxtacldc.jar
Implementation of J2ME Chat
6. MIDlet
Run : chat project  right click  run project
Implementation of J2ME Chat
MIDlet
Related files and locations

Chat source code


JAD:


\jxme-2.1.3-bin\midp\demo\chat
\jxme-2.1.3-bin\midp\demo\chat\bin\chat.jad
Library:

\jxme-2.1.3-bin\midp\demo\chat\lib\jxta-cldc.jar
Implementation of JXME Proxy
1. New project  General project  Java Application
Implementation of JXME Proxy
2. name proxy  finish
Implementation of JXME Proxy
3. New Java class  place the code which we provide
Implementation of JXME Proxy
 Code:
package tommy;
import java.io.File;
import net.jxta.platform.NetworkManager;
public class StartJXME_Proxy {
private NetworkManager manager;
public StartJXME_Proxy() {
}
private void startProxy() {
try {
manager = new NetworkManager(NetworkManager.ConfigMode.PROXY,
"ProxyeServer", new File(new File(".cache"), "ProxyeServer").toURI());
manager.startNetwork();
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
public static void main(String[] args){
StartJXME_Proxy startJXME_proxy = new StartJXME_Proxy();
startJXME_proxy.startProxy();
}
}
Implementation of JXME Proxy
4. Add libraries Libraries  Add Jar/folder\jxse-lib-2.5\*.jar
Implementation of JXME Proxy
5. Run  project  right click  run project
References and Resources








Getting Started with JXTA for J2ME,
http://developers.sun.com/mobility/midp/articles/jxme/index.html
JXTA, https://jxta.dev.java.net/
JXTA v2.0 Protocol Specification, https://jxtaspec.dev.java.net/
JXTA Community Forum,
http://forums.java.net/jive/forum.jspa?forumID=50&start=0
JXTA JXSE Programmers Guide, https://jxtaguide.dev.java.net/
J2ME tutorials,
http://developers.sun.com/mobility/learning/tutorial/
Sun Java Wireless Toolkit ,
http://java.sun.com/products/sjwtoolkit/download.html
NetBeans, http://www.netbeans.org/
References and Resources

Code in Netbeans Project:



網路硬碟二:share name  XML-JXME
Maybe you need to correct the location of libraries
Public JXME proxy:





http://rdv.jxtahosts.net/cgi-bin/relays.cgi?2
http://192.18.37.36:9700
http://192.18.37.37:9700
http://192.18.37.38:9700
http://192.18.37.39:9700