Opening a URL connection in your mobile phone

Streams can be opened in several ways

1. HTTP communication:

Connection hc = Connector.open("http://www.wirelessdevnet.com");

2. Stream-based Socket communication:

Connection sc = Connector.open("socket://localhost:9000");

3. Datagram-based socket communication:

Connection dc = Connector.open("datagram://:9000");

4. Serial port communication:

Connection cc = Connector.open("comm:0;baudrate=9000");

5. File I/O

Connection fc = Connector.open("file://foo.dat");

I have used the HTTP communication.

HttpConnection c = (HttpConnection) Connector.open(url.getString());
this.responseCode = c.getResponseCode();
c.close();

While running, I got a warning in the log says…

Warning: To avoid potential deadlock, operations that may block, such as networking,
should be performed in a different thread than the commandAction() handler.

In addition, the phone emulator is not responding for the alert 😦

mobiletest Midlet Suite wants to connect to http:///...... using airtime. This may result in charges.
Is it OK to use airtime?

No response for this alert when I press yes or no several times!

http://forums.sun.com/thread.jspa?threadID=5339547

We need to write the HTTP connection in a separate thread, so that the main thread wont get blocked with it.

———
Ref. http://www.wirelessdevnet.com/channels/java/features/j2me_http.phtml

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s