IT tutorials
 
Mobile
 

Java ME on Symbian OS : Networking and General Connection Framework (part 1)

11/5/2011 3:21:41 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
Now that we have considered in detail the MIDP Security Model, let's learn more about the networking APIs in the specification, provided through the Generic Connection Framework (GCF).

Symbian's implementation of MIDP complies with the specification, providing implementations of the following protocols:

  • HTTP

  • HTTPS

  • Sockets

  • Server sockets

  • Secure sockets

  • Datagrams

  • Serial port access.

The local connectivity protocol (serial port access) is similar in nature to the network protocols, but its connection string depends on the target handset model, therefore you must study it separately.

1. HTTP and HTTPS Support

To open an HTTP connection we use the Connector.open() method with a URL of the form www.myserver.com. Code to open an HttpConnection and obtain an InputStream would look something like this:

try{
String url = "www.myserver.com";
HttpConnection conn = (HttpConnection)Connector.open(url);
InputStream is = conn.openInputStream();
...
conn.close()
}
catch(IOException ioe){...}

Under the MIDP security model, untrusted MIDlets can open an HTTP connection only with explicit user confirmation. Signed MIDlets that require access to an HTTP connection must explicitly request permission:

MIDlet-Permissions: javax.microedition.io.Connector.http, ...

Opening an HTTPS connection follows the same pattern as a normal HTTP connection, with the exception that we pass in a connection URL of the form https://www.mysecureserver.com and cast the returned instance to an HttpsConnection object, as in the following example:

try{
String url = "https://www.mysecureserver.com";
HttpsConnection hc = (HttpsConnection)Connector.open(url);
InputStream is = hc.openInputStream();
...
hc.close()

...
}
catch(IOException ioe){...}

The security policy related to access permissions by trusted and untrusted MIDlets is the same as the one for HTTP connections, except that the permission setting has a different name:

MIDlet-Permissions: javax.microedition.io.Connector.https, ...

2. Socket and Server Socket Support

MIDP makes support for socket connections a recommended practice. Socket connections come in two forms: client connections, in which a socket connection is opened to another host; and server connections in which the system listens on a particular port for incoming connections from other hosts. The connections are specified using Universal Resource Identifiers (URI). You should be familiar with the syntax of a URI from web browsing. They have the format <string1>://<string2><string1> identifies the communication protocol to be used (e.g., http) and <string2> provides specific details about the where connection. The protocol may be one of those supported by the Generic Connection Framework .

To open a client socket connection to another host, we pass a URI of the following form to the connector's open() method:

socket://www.symbian.com:5000

The host may be specified as a fully qualified hostname or IP address and the port number refers to the connection endpoint on the remote peer. Some sample code is shown below:

SocketConnection sc = null;
OutputStream out = null;
try{
sc = (SocketConnection)Connector.open ("socket://200.251.191.10:7900");
...
out = c.openOutputStream();
...
}
catch(IOException ioe){...}

A server socket connection is used to listen for inbound socket connections. To obtain a server socket connection, we can pass a URI in either of the following forms to the connector's open() method:

socket://:79
socket://

In the first case, the system listens for incoming connections on port 79 (of the local host). In the latter case, the system allocates an available port for the incoming connections.

ServerSocketConnection ssc = null;
InputStream is = null;
try{
ssc = (ServerSocketConnection)Connector.open("socket://:1234");
SocketConnection sc = (SocketConnection)ssc.acceptAndOpen();
...
is = sc.openInputStream();
...
}
catch(IOException ioe){...}

The ServerSocketConnectioninterface extends the Stream-ConnectionNotifier interface. To obtain a connection object for an incoming connection the acceptAndOpen() method must be called on the ServerSocketConnection instance. An inbound socket connection results in the call to the acceptAndOpen() method, returning a StreamConnection object which can be cast to a SocketConnection as desired.

A signed MIDlet suite containing MIDlets which open socket connections must explicitly request the appropriate permissions:

MIDlet-Permissions: javax.microedition.io.Connector.socket,
javax.microedition.io.Connector.serversocket, ...

If the protection domain to which the signed MIDlet suite would be bound grants, or potentially grants, these permissions, then the MIDlet suite is installed and the MIDlets it contains will be able to open socket connections. This can be done either automatically or with user permission, depending upon the security policy in effect on the device for the protection domain to which the MIDlet suite has been bound.

Whether MIDlets in untrusted MIDlet suites can open socket connections depends on the security policy relating to the untrusted domain in force on the device.

3. Secure Socket Support

Secure socket connections are client socket connections over SSL. To open a secure socket connection we pass in a hostname (or IP address) and port number to the connector's open() method using the following URI syntax:

ssl://hostname:port

We can then use the secure socket connection in the same manner as a normal socket connection, for example:

try{
SecureConnection sc = (SecureConnection)
Connector.open("ssl://www.secureserver.com:443");
...
OutputStream out = sc.openOutputStream();
...
InputStream in = sc.openInputStream();
...
}
catch(IOException ioe){...}

A signed MIDlet suite that contains MIDlets which open secure connections must explicitly request permission:

MIDlet-Permissions: javax.microedition.io.Connector.ssl, ...

If the protection domain to which the signed MIDlet suite would be bound grants, or potentially grants, this permission, the MIDlet suite can be installed and the MIDlets it contains will be able to open secure connections. This can be done automatically or with user permission, depending on the security policy in effect. Whether untrusted MIDlets can open secure connections depends on the permissions granted in the untrusted protection domain.

4. Datagram Support

Symbian's MIDP implementation includes support for sending and receiving UDP datagrams. A datagram connection can be opened in client or server mode. Client mode is for sending datagrams to a remote device. To open a client-mode datagram connection we use the following URI format:

datagram://localhost:1234

Here the port number indicates the port on the target device to which the datagram will be sent. Sample code for sending a datagram is shown below:

String message = "Hello!";

byte[] payload = message.toString();
try{
UDPDatagramConnection conn = null;
conn = (UDPDatagramConnection)
Connector.open("datagram://localhost:1234");
Datagram datagram = conn.newDatagram(payload, payload.length);
conn.send(datagram);
}
catch(IOException ioe){...}

Server mode connections are for receiving (and replying to) incoming datagrams. To open a datagram connection in server mode, we use a URI of the following form:

datagram://:1234

The port number in this case refers to the port on which the local device is listening for incoming datagrams. Sample code for receiving incoming datagrams is given below:

try{
UDPDatagramConnection dconn = null;
dconn = (UDPDatagramConnection)Connector.open("datagram://:1234");
Datagram dg = dconn.newDatagram(300);
while(true){
dconn.receive(dg);
byte[] data = dg.getData();
...
}
}
catch(IOException ioe){...}

A signed MIDlet suite which contains MIDlets that open datagram connections must explicitly request permission to open client connections or server connections:

MIDlet-Permissions: javax.microedition.io.Connector.datagram,
javax.microedition.io.Connector.datagramreceiver, ...

If the protection domain to which the signed MIDlet suite would be bound grants, or potentially grants, the requested permissions, the MIDlet suite can be installed and the MIDlets it contains will be able to open datagram connections. This can be done automatically or with user permission, depending on the security policy in effect. Whether untrusted MIDlets can open datagram connections depends on permissions granted to MIDlet suites bound to the untrusted protection domain.

 
Others
 
- jQuery 1.3 : Effects - Basic hide and show
- jQuery 1.3 : Effects - Inline CSS modification
- Mobile Web Apps : Events
- Mobile Web Apps : Setting up Shop
- iPhone 3D Programming : Simplify with glDrawTexOES
- iOS SDK : Adding a SQLite Database
- The Anatomy of a Mobile Site : Navigation and menu systems (part 3) - Paving Mobile Pathways & Switcher Links
- The Anatomy of a Mobile Site : Navigation and menu systems (part 2) - Breadcrumbs, Header and Footer Navigation
- The Anatomy of a Mobile Site : Navigation and menu systems (part 1) - Navigational Lists & Decorating Menus
- iPad Troubleshooting : No Sound in Music or Video
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us