an introduction to the java me project jens a andersson
TRANSCRIPT
An Introduction to the Java ME Project
Jens A Andersson
2/12
Agenda
Java ME MIDlets NetBeans Your task: The Application Simple Session Protocol and SSPServer SSP help classes Why Threads
3/12
Java ME
Sun groupes its Java technologies into 3 editions:• Java EE (Java Enterprise Edition) - servers• Java SE (Java Standard Edition) – personal computers• Java ME (Java Micro Edition) – mobile phones and
PDAs
In this course we will use:• MIDP (Mobile Information Device Profile)
• MIDP 1.0, 2.0, and 2.1 – backward compatible• CDLC (Connected Limited Device Configuration)
• CLDC 1.0 and 1.1 – backward compatible
4/12
MIDlets
An application written for MIDP is called a MIDlet.
All MIDlets extend the MIDlet class:• public class MyMIDlet extends MIDlet { }
The MIDlet class provides methods for starting, pausing, and terminating the MIDlet application:
• startApp()• pauseApp()• destroyApp(boolean unconditional)
The department has four Sony Ericsson K700 phones that support MIDP 2.0.
5/12
A Complete MIDlet Example
import javax.microedition.midlet.*;import javax.microedition.lcdui.*;
public class HelloMIDlet extends MIDlet { public void startApp() { TextBox textBox = new TextBox(“My MIDlet", "Hello world :=)",15,0); Display.getDisplay(this).setCurrent(textBox); } public void pauseApp() { } public void destroyApp(boolean unconditional) { }}
6/12
NetBeans
NetBeans is a free and open-source IDE (Integrated Development Environment) for developing Java applications.
NetBeans runs on Windows, Linux, Mac OS, etc. It has support for CLDC 1.0/1.1 and MIDP
1.0/2.0/2.1. With NetBeans you can write, emulate, and
debug applications for mobile phones. So they contain all you need to develop Java ME applications.
Application (overview)
Peer-to-peer application: Of your choice Minimum: Simple chat application
Two mobile devices communicate and exchange messages
Session server (hub/proxy) to find other party
Application (considerations)
Hub to find other partyNAT makes it impossible to
communicate directly between mobile devices
Proxy for two-way communication (tunnelling)
Application (figure)
NAT!
Private addresses
Private addressesGlobal addresses
NAT & PAT
NAT = Network Address TranslationPAT = Port and network Address
Translation
zFigure 19.27 Translation
Alternative: Source address 200.24.5.8 goes here
Simple Session Protocol
SSPUDP basedControl messagesData/Tunnel messages
13/12
The SSPServer
SSP (Simple Session Protocol) is a simple protocol developed for this course.
SSPServer is a Java SE application and allows mobile phones to communicate to each other through a server.
Two ways of using the SSPServer:• Download and run it locally on any computer –
connect your application to port 3333 on localhost• No downloading needed - connect your mobile
phone to port 3333 on sspserver.eit.lth.se (public address)
SSPServer
Users login/logoutHolds a list of active users/opponentsControls state also on clientsReacts only on incoming packets
(no time outs)
Forwards application data to other party TUNNEL
SSP packet format
TYPE ID CONTROL 0x01
• (The following data is control data)
TUNNEL 0x02• (The following data is application data)
TYPE ID (1) DATA (variable)
Control Header Format
CTRL TYPE ID LOGIN REQ 0x11
• (The user logs in with the specified user id)
LOGIN ACC 0x12• (The user login is accepted by the hub)
LOGIN REJ 0x13• (The user login is rejected by the hub)
LOGIN ERR 0x1f• (Server in LOGIN state but receives ctrl packet for other
state)
TYPE ID (1)
0x01CTRL TYPE ID (1)
USER ID (8) PEER ID (8)
Control Header Format (cont)
TERMINATE REQ 0x21
• (The user/hub terminates and is logged out)
SETUP LST REQ 0x04• (The user requests a list over available opponents
from the hub)
SETUP LST RES 0x05• (The hub sends a list with available opponents)
Control Header Format (cont)
SETUP REQ 0x01• (The user requests the specified user as an
opponent)
SETUP ACC 0x02• (The user accepts request from other user)
SETUP REJ 0x03• (The user rejects request from other user)
These ctrl packets are forwarded by the hub to the users.
Peer lists
SETUP LST RES List of available opponents From Hub to mobile device
CONTROL HEADER (16)
NBR PEERS (1)
PEER1 (8)
PEER2 (8)
PEER3 (8) ...
Tunnel Header Format
USERID = you; PEERID = opponentYour application protocol goes in
the DATA field
TYPE ID (1 )
0x02RESERVED (1 )
USER ID (8) PEER ID (8) DATA (variable)
Application Sequence
Login to serverIf accepted
get user list select peer request session with peer
If accepted Start ”application” and data transfer in tunnel
At end logout from server
SSP Java class
Methods for datagram Parse request Build request Validate request
See API on project web page for details http://www.eit.lth.se/index.php?
id=javame
ByteString Java Class
Application data type = StringDatagramConnection
(sending/recieving UDP datagram) uses byte[ ]
ByteString: ”interface” between String and byte[ ]
See API on course home page for details
Application protocol
Data transfer in UDP based tunnel Best effort!
Application shall handle errors! Time outs Packet loss Packet out of sequence
How? You decide! Select/Design error handling method
Tunnel Header Format
Your application protocol goes in the DATA field
TYPE ID (1 )
0x02RESERVED (1 )
USER ID (8) PEER ID (8) DATA (variable)
Applications protocol (cont.)
Is control information needed?Keep track of
messages/datagrams/packets?How is DATA field interpreted?…
This is your task for section 2
GUI
GUI is handled by main thread
inhibited when waiting for response in your methods Send REQ, Get response Wait for move from opponent
GUI events must be handled!
An application
MyMIDlet
startApp
commandAction
“The Application”
An application (cont.)
MyMIDlet
startApp
commandAction
.
.
wait for response
.
“The Application”
GUI“stalled”
An application (cont..)
MyMIDlet
startApp
commandAction
.
.
wait for response in thread
.
“The Application”
GUI active
Threads (cont.)
Send REQ application waiting for GPRS setup? application waiting for free GPRS slots? application sending datagram?
GUI blocked until Send REQ is completed
Threads (cont..)
Get Response application setup GPRS etc? application waiting for incoming
datagram? application waiting for response from
opponent?
GUI blocked until Get Response request is completed
Threads (cont…)
Do in parallel thread Send REQ Get Response
In main thread Wait for completion of parallel threads Handle GUI exceptions
36/12
Get Started!
1) Visit the home page of the project: http://www.eit.lth.se/index.php?id=javame
2) Download the SSPServer and run it locally.
3) Download the skeleton code and run it.
4) Study and understand the structure of the skeleton code.