Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Introduction to the Java ME Project Jens A Andersson.

Similar presentations


Presentation on theme: "An Introduction to the Java ME Project Jens A Andersson."— Presentation transcript:

1 An Introduction to the Java ME Project Jens A Andersson

2 2/12 Agenda  Java ME  MIDlets  NetBeans  Your task: The Application  Simple Session Protocol and SSPServer  SSP help classes  Why Threads

3 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 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 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 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.

7 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

8 Application (considerations) Hub to find other party NAT makes it impossible to communicate directly between mobile devices Proxy for two-way communication (tunnelling)

9 Application (figure) NAT! Private addresses Global addresses

10 NAT & PAT NAT = Network Address Translation PAT = Port and network Address Translation

11 zFigure 19.27 Translation Alternative: Source address 200.24.5.8 goes here

12 Simple Session Protocol SSP UDP based Control messages Data/Tunnel messages

13 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)

14 SSPServer Users login/logout Holds a list of active users/opponents Controls state also on clients Reacts only on incoming packets  (no time outs) Forwards application data to other party  TUNNEL

15 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)

16 Control Header Format CTRL TYPE ID  LOGIN REQ0x11 (The user logs in with the specified user id)  LOGIN ACC0x12 (The user login is accepted by the hub)  LOGIN REJ0x13 (The user login is rejected by the hub)  LOGIN ERR0x1f (Server in LOGIN state but receives ctrl packet for other state) TYPE ID (1) 0x01 CTRL TYPE ID (1) USER ID (8)PEER ID (8)

17 Control Header Format (cont)  TERMINATE REQ0x21 (The user/hub terminates and is logged out)  SETUP LST REQ0x04 (The user requests a list over available opponents from the hub)  SETUP LST RES0x05 (The hub sends a list with available opponents)

18 Control Header Format (cont)  SETUP REQ0x01 (The user requests the specified user as an opponent)  SETUP ACC0x02 (The user accepts request from other user)  SETUP REJ0x03 (The user rejects request from other user) These ctrl packets are forwarded by the hub to the users.

19 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)...

20 Tunnel Header Format USERID = you; PEERID = opponent Your application protocol goes in the DATA field TYPE ID (1 ) 0x02 RESERVED (1 )USER ID (8)PEER ID (8) DATA (variable)

21 Application Sequence Login to server If accepted  get user list  select peer  request session with peer If accepted  Start ”application” and data transfer in tunnel At end logout from server

22 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

23 ByteString Java Class Application data type = String DatagramConnection (sending/recieving UDP datagram) uses byte[ ] ByteString: ”interface” between String and byte[ ] See API on course home page for details

24 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

25 Tunnel Header Format Your application protocol goes in the DATA field TYPE ID (1 ) 0x02 RESERVED (1 )USER ID (8)PEER ID (8) DATA (variable)

26 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

27 Implementation Section 3 is implementation of your application and application protocol Your application should work on mobile terminals

28 Threads Parallel processing  sections of code running executed “simultaneously” Mobile phone Java application already threaded!  runs main thread  Calls MIDlet methods threaded startApp, pauseApp, destroyApp commandAction

29 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!

30 An application MyMIDlet startApp commandAction “The Application”

31 An application (cont.) MyMIDlet startApp commandAction. wait for response. “The Application” GUI “stalled”

32 An application (cont..) MyMIDlet startApp commandAction. wait for response in thread. “The Application” GUI active

33 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

34 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

35 Threads (cont…) Do in parallel thread  Send REQ  Get Response In main thread  Wait for completion of parallel threads  Handle GUI exceptions

36 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.


Download ppt "An Introduction to the Java ME Project Jens A Andersson."

Similar presentations


Ads by Google