This seminar presents an overview of networking and local connectivity of Java ME platform: HTTP, Sockets, Datagrams, messaging, Bluetooth, serial and RFID.
3. Agenda
• Generic Connection Framework
– Networking
• Basic: HTTP/HTTPS
• Low-level: socket, serversocket, datagrams
• Messaging
• Web Services
• Multimedia
– Local connectivity:
• Bluetooth
• IrDA & Serial ports
• Near Field Communication
• Conclusions
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
4. Agenda
• Generic Connection Framework
– Networking
• Basic: HTTP/HTTPS
• Low-level: socket, serversocket, datagrams
• Messaging
• Web Services
• Multimedia
– Local connectivity
• Bluetooth
• IrDA & Serial ports
• Near Field Communication
• Conclusions
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
5. Java ME: made for connectivity
• Many optional APIs for the Java ME platforms
have been designed to support remote and
local connectivity on consumer handsets
• Manufacturers
can add and
remove support
for protocols with
no impact to the
whole runtime
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
6. Generic Connection Framework
• The Generic Connection Framework (GCF) is
the core library component that provides
dynamic access to any communication
protocol with a standard interface
• The Connector factory creates connections
according to URI schemas and protocols:
Protocols:
Connection connection = Connector.open(SCHEMA); - HTTP/HTTPS
- Socket/SecureSocket
InputStream input = connection.openInputStream(); - ServerSocket
- Datagram
OutputStream output = connection.openOutputStream(); - Serial (Comm & IrDA)
- SMS/MMS
- Bleutooth
// your logic here! :-) - Contactless (NFC)
connection.close();
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
7. Agenda
• Generic Connection Framework
– Networking
• Basic: HTTP/HTTPS
• Low-level: socket, serversocket, datagrams
• Messaging
• Web Services
• Multimedia
– Local connectivity:
• Bluetooth
• IrDA & Serial ports
• Near Field Communication
• Conclusions
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
8. Basic networking
• The MIDP Profile requires Java runtime
environment to support both HTTP and HTTPS
connections
• HttpConnection and HttpsConnection
encapsulate HTTP protocol:
HttpConnection connection;
connection = (HttpConnection) Connector.open(“http://www.jmdf.org”);
InputStream input = connection.openInputStream();
if (connection.getResponseCode() == HttpConnection.OK) {
// you can now download the web page...
}
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
9. Low-level networking
• Low-level networking library is key
requirement for instant messaging, M2M
communication
• A MIDP device may support direct access to
transport-level protocols TCP and UDP, in both
client and server mode:
– Socket, ServerSocket, Datagram
Connector.open(“socket://www.myhost.it:3040”);
Connector.open(“socket://:3040”); // creates a listening connection
Connector.open(“datagram://updserver.myhost.it:4556”);
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
10. Messaging
• SMS and MMS are most popular facilities since
the advent of 2G mobile telephony
• JME supports short text, binary and multipart
messages on the Wireless Messaging API:
– JSR 120: SMS
– JSR 205: MMS
• MIDlets can send/receive messages to/from a
registered port (as in TCP/UDP connections)
using the schema: sms://RECIPIENT:PORT
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
11. Messaging
• GCF and custom classes manage message
dispatch and notification
SENDING A MESSAGE:
String recipient = "sms://+391234567890:12345";
MessageConnection conn;
conn = (MessageConnection) Connector.open(recipient);
TextMessage msg = (TextMessage)
conn.newMessage(conn.TEXT_MESSAGE);
msg.setPayloadText("Hello World!");
• MIDP 2.0 Push conn.send(msg);
Registry lets RECEIVING A MESSAGE:
MIDlets to be MessageConnection c;
c = (MessageConnection) Connector.open("sms://:12345");
registered on Message msg = c.receive();
if (msg instanceof TextMessage) {
an assigned port TextMessage tmsg = (TextMessage)msg;
// Handle the text message...
}
and executed
when a message has been received
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
12. Web services
• Access to web services is provided by the WSA
(Web Services API, JSR 172) MIDlet
• Stub generators create Stub
mobile-side client
interface automatically
WSA Service Provider
using WSDL Interface
JAXP JAX-RPC
Compatibility is limited
to WS-I Basic Profile 1.0 MIDP/PP
CLDC/CDC
• Lightweight Web Services (REST/JSON) can be
supported using basic HttpConnection
(GET/POST) and JAXP subset of JSR 172
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
13. Multimedia
• Mobile Media API (JSR 135) enables audio and
video playback and recording
• It supports standard download,
progressive download and
RTSP
RTSP
• Custom
DataSources
can be HTTP
implemented to support (Progressive download)
new protocols and servers
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
14. Multimedia
• Transport is nearly neutral for developers:
Manager and Player classes hide all details
related to protocols, formats and encodings
• Easy to play a song using HTTP:
Player player = Manager.createPlayer(“http://myhost.it/song.mp3”);
player.realize();
player.prefetch();
player.start();
3Player plays any kind of music
source (even with DRM) using
MMAPI and custom datasources
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
15. Multimedia
• Easy to play a video using RTSP:
Player player = Manager.createPlayer(“rtsp://myhost.it/video.3gp”);
player.realize(); player.prefetch();
VideoControl vc = (VideoControl) player.getControl(“VideoControl”);
vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, aCanvas);
vc.setVisible(true);
player.start();
BeeTV plays seamlessly live
and video-on-demand channels
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
16. Agenda
• Generic Connection Framework
– Networking
• Basic: HTTP/HTTPS
• Low-level: socket, serversocket, datagrams
• Messaging
• Web Services
• Multimedia
– Local connectivity
• Bluetooth
• IrDA & Serial ports
• Near Field Communication
• Conclusions
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
17. Local connectivity
• Computer is ubiquitous: any object can be
equipped with an small embedded CPU and
some wireless module
• Local connectivity (aka ad-hoc networking) is
the ability of any device to transmit and
receive data with its surroundings
• Java ME provides a rich set
of optional APIs to access
common wireless and wired
devices
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
18. Bluetooth
• Bluetooth is the leading consumer technology
for local connectivity: peripherals, P2P
networks, environment awareness...
MASTER MASTER
• JSR 82 (Bluetooth API) provides powerful
interface to device and service discovery,
L2CAP and RFCOMM connections, OBEX Push
client and server
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
19. Bluetooth
• Four lines of code to open connection to a
Bluetooth GPS and read NMEA connect to the
RFCOMM serial port and read data:
gps = “btspp://0002C71536EA:1;authenticate=false;encrypt=false;master=false";
StreamConnection conn = (StreamConnection) Connector.open(gps);
buffer = new BufferedReader(new InputStreamReader(conn.openInputStream()));
// it's time to read the first line:
String nmea_sentence = buffer.readLine();
• NMEA sentences contain position data:
Satellites
$GPGGA,164922.982,3859.4108,N,00856.1785,E,1,04,3.4,127.9,M,47
.6,M,0.0,0000*7A
Latitude Longitude Altitude
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
20. IrDA & Serial Ports
• Embedded modules often use old-fashioned
infrared and serial ports. These interfaces are
still in use for industrial applications to access
IrDA printers, barcode and RFID readers...
• The GCF provides transparent access to them:
Connector.open(“comm:com0;baudrate=19200”);
• Example: Windows Mobile PDAs
have CompactFlash socket for
enhanced peripherals
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
21. Near Field Communication
• Near Field Communication (NFC) is a new,
short-range wireless connectivity technology
that evolved from contactless identification
and interconnection technologies
• JSR 257 (Contactless API) provides
full support for reading/writing
mode of ISO 14443 tags and
inter-device communication
• Nokia 6131 NFC is the first
device compatible with this API
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
22. Network Monitor
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
23. Conclusions
• Java ME has been designed “with networking
and connectivity in mind”
• The Generic Connection
Framework provides
homogeneous access to
any I/O interface for both
remote and local connectivity
• Upcoming networking standard are under
specification and will be seamlessly integrated
in next-generation Java ME runtimes
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
24. About me
• Stefano Sanna
– Website: http://www.gerdavax.it
– Email: gerdavax@tiscali.it
• Java Mobile Developers Forum
– Website: http://www.jmdf.org
• Beeweeb Technologies
– Website: http://www.beeweeb.com
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org
25. Thank you :-)
Java ME
Networking & Connectivity
(Versione 1.0)
(C) 2007 Stefano Sanna
http://www.gerdavax.it - gerdavax@tiscali.it
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU
Free Documentation License, Version 1.2 or any later version published by the Free Software
Foundation. Please, find a copy of the license at: http://www.gnu.org/copyleft/fdl.html
http://www.gnu.org/copyleft/fdl.html
Java ME Connectivity Overview – ActionScript.it and JMDF online Meeting, 21-03-2007 - http://www.jmdf.org