1 / 34

An Introduction to the Java ME Project

An Introduction to the Java ME Project. Jens A Andersson. Agenda. Java ME MIDlet s NetBeans Your task: The Application Simple Session Protocol and SSPServer SSP help classes Why Threads. Java ME. Sun groupes its Java technologies into 3 editions:

siran
Télécharger la présentation

An Introduction to the Java ME Project

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An Introduction to the Java ME Project Jens A Andersson

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

  3. 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. 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. 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. 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 NetBeansyou 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. NAT! Global addresses Private addresses Private addresses Application (figure)

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

  11. Figure 19.27Translation Alternative: Source address 200.24.5.8 goes here

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

  13. 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. TYPE ID (1) DATA (variable) SSP packet format • TYPE ID • CONTROL 0x01 • (The following data is control data) • TUNNEL 0x02 • (The following data is application data)

  16. TYPE ID (1) 0x01 CTRL TYPE ID (1) USER ID (8) PEER ID (8) 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)

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

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

  19. CONTROL HEADER (16) NBR PEERS (1) PEER1 (8) PEER2 (8) PEER3 (8) ... Peer lists • SETUP LST RES • List of available opponents • From Hub to mobile device

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

  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. TYPE ID (1 ) 0x02 RESERVED (1 ) USER ID (8) PEER ID (8) DATA (variable) Tunnel Header Format • Your application protocol goes in the DATA field

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

  28. An application “The Application” MyMIDlet startApp commandAction

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

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

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

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

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

  34. Get Started! • Visit the home page of the project: http://www.eit.lth.se/index.php?id=javame • Download the SSPServer and run it locally. • Download the skeleton code and run it. • Study and understand the structure of the skeleton code.

More Related