Networking in Java ME

Mobile Information Device 2.0 (JSR-118) specification includes support for the Generic Connection Framework (GCF), defined in the javax.microedition.io package of the Connected Limited Device Configuration (CLDC) 1.0 specification. This package allows you to use networking and push registry functions.

These networking functions include support for HTTP and HTTPS connections, as well as support for straight TCP, serial port, and Secure Socket Communication. In addition to those, with the support for push registry MIDlets can receive incoming communication requests and register for network connection events. UDP is not supported.

Extended networking features

The javax.microedition.io package only provides very basic networking possibilities. However, APIs such as Web Services and Bluetooth have been created to allow for more extended features.

The Java ME™ Web Services specification (including JSR-172 specification (RCP) and JSR-172 specification (XML) was created in order to allow support for XML parsing and the ability to invoke Web Services. The API contains two optional packages for XML processing and Web Services. These two packages are independent and thus a device may have either one or both of them.

The Java APIs for Bluetooth (JSR-82) specification defines APIs that can be used to exercise certain Bluetooth protocols defined in the Bluetooth specification volume 1, and certain profiles defined in the Bluetooth specification volume 2. For more information about these profiles, see the Java APIs for Bluetooth (JSR-82) specification. The Bluetooth API is defined in such a way as to make it possible for additional and future profiles to be built on top of this API. This assumes that future changes to the Bluetooth specification remain compatible with this API.

The Bluetooth technology itself is an industrial specification for wireless personal area networks (PANs). The Bluetooth technology provides a way to connect and exchange information between devices such as personal digital assistants (PDAs), mobile devices, laptops, PCs, printers, digital cameras and video game consoles via a secure, globally unlicensed short-range radio frequency.

Networking protocols

The following table specifies the GCF Connections and the protocols used for implementing them.

Table: Supported protocols in Series 40 and Nokia Asha software platform devices

Connection interface

Networking protocol used

Notes

HttpConnection

HTTP or WAP WSP protocol

 

HttpsConnection

HTTPS (i.e. HTTP over TLS) or WAP WTLS (WSP) protocol

 

SecureConnection

TLS or SSLv3

 

ServerSocketConnection

TCP/IP (server side)

 

SocketConnection (TCP)

TCP/IP (client side)

 

CommConnection

physical RS-232 serial port, IrDA IrCOMM, USB, BT

Supported port types (COM, IR, USB, BT) depend on device hardware.

PushRegistry

List of supported protocols in Series 40:

  • Bluetooth RFCOMM

  • Bluetooth L2CAP

  • SMS

  • MMS

 

Support for user-selected MIDlet settings in Series 40

From Java Runtime 1.0.0 for Series 40 onwards, the user is allowed to change the Configuration Settings for each MIDlet on single-SIM devices. The sub-menu is added under the MIDlet Options menu, under the Applications Settings option. This allows the user to select from the available access point settings for different Configurations and Accounts. For more information about the Configuration Settings supported by a device, see the device's user guide.

Network prompts

Series 40 and Nokia Asha software platform devices does not generally support access point selection. In devices that support WLAN, access point selection is prompted when WLAN is available and no WLAN tagged as "automatic" is found.

Output streams

Java ME utilizes two output streams, System.out() and System.err(). If your application requires that bytes are written to the output stream, and have to be sent immediately, then call the os.flush method right after the os.write method to ensure that buffered output bytes are written out.

OutputStream os;
...
os.write("hello".getBytes());
os.flush();
...

Input stream

It is not recommended to simultaneously read both InputStreamReader and the InputStream used in its creation, as it can lead to unexpected behavior.

Push Registry and datagram protocol

If a MIDlet registers a datagram connection, then the network connection is always on even when no MIDlets are running. For more information see Push applications.

Note: Sites like Facebook and Twitter set multiple cookies for authentication and authorization using Set-Cookie headers. On the Series 40 platform, the HTTP stack for Java could not read multiple header values of the same header. It could retrieve only one of the Set-Cookie headers, and set only one cookie. This caused the authentication to these sites to fail. This issue is now resolved. The HTTPConnection.getHeaderField() method returns multiple header values of a header separated by comma.