Getting started with JXTA for J2ME

farrightΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 6 χρόνια και 3 μήνες)

443 εμφανίσεις

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


JXME Proxy

(Relay)

DEMO


JXTA demonstration programs for MIDP


Chat MIDlet

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 set
-
top 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


A framework


Why JXME ?


The c
onstraints of Mobile Device


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.
J2ME peer send
HTTP request messages

to a JXTA relay

2.
JXTA relay parse each name
-
value pair in the
HTTP request


XML messages (JXTA format)


relay the messages over the
JXTA network

3.
JXTA relay receives a message from the JXTA network


parse
the XML format of the incoming message



author a
corresponding
HTTP response

4.
Wait for the J2ME peer to send an
HTTP poll request



send the
HTTP response back to the J2ME peer

1.

2.

3.

4.

Response

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, platform
-
independent 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 ?


Cost: GPRS, 3G …?


Mobile device: Power consumption, UI ?



In the future


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



JXTA core


JMEX Proxy libraries


jxme
-
2.1.3
-
bin.zip



JXME framework


Chat MIDlet code and libraries


Tools:


NetBeans (6.0) + Mobility pack


http://www.netbeans.org/

Implementation of J2ME Chat MIDlet

1. New project

䵯M楬攠


浯扩汥l灲潪散琠晲潭⁥硩t瑩t朠䵉䑐⁳潵牣e

Implementation of J2ME Chat MIDlet

2. Specify the source and JAD file

Implementation of J2ME Chat MIDlet

3. Name and Location


湡浥


捨ct

Implementation of J2ME Chat MIDlet

4. Default Platform Selection : use default

Implementation of J2ME Chat MIDlet

5. Add library : chat porject


物杨琠捬楣c


灲潰敲瑩敳


慤搠䩡爯婩瀠


橸瑡
-
捬摣⹪慲

Implementation of J2ME Chat MIDlet

6. Run : chat project


物杨琠捬楣c


牵渠灲潪散t

Implementation of J2ME Chat MIDlet

Related files and locations


Chat source code


\
jxme
-
2.1.3
-
bin
\
midp
\
demo
\
chat


JAD:


\
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


䝥湥G慬⁰牯橥r琠


䩡v愠A灰汩捡瑩tn

Implementation of JXME Proxy

2. name


灲潸p


晩f楳i

Implementation of JXME Proxy

3. New Java class


灬慣攠瑨攠捯e攠w桩h栠w攠灲潶楤e

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

䱩扲慲楥i


A摤 䩡爯景r摥d

\
橸je
-
汩l
-
㈮2
\
⨮橡*

Implementation of JXME Proxy

5. Run


灲潪散琠


物杨琠捬楣c


牵渠灲潪散t

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://jxta
-
spec.dev.java.net/


JXTA Community Forum,

http://forums.java.net/jive/forum.jspa?forumID=50&start=0


JXTA JXSE Programmers Guide
,
https://jxta
-
guide.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