HTTP connection on Nokia S60 2nd FP2
Hi, I'm developing an application in J2ME that needs to use HTTP connection. In a first approach only dowloads a byte to test the connection and it works fine on NetBeans emulator, on WTK 2.5.1, on Nokia emulator (for S60 3rd FP1), and on Nokia E61, but does NOT work on Nokia emulator (for S60 2nd FP2) and on Nokia 6630. The problem is allways on the same OS, this is Symbian OS v8.0a...
Note: when I say that does not work I mean that doesn't do anything, no error, no exception, only stops, and remains stopped. You can exit, but is the only thing that you can do.
So, is there any way to resolve this?
How can I make a "simple"? HTTP connection?
This is my stupid sample code...:
import java.io.*;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Display;
/**
*
* @author jose
*/
publicclass TestConnection{
/**instance to stablish the HTTP connection*/
private HttpConnection mHttpConnection=null;
/**variable to indicate if the program is cancelled*/
privateboolean bTestOK=false;
/**output stream to server*/
private DataOutputStream dout =null;
/**output stream from server*/
private DataInputStream din =null;
/**Response from server*/
public String stResponse="";
/** Creates a new instance of TestConnection */
public TestConnection(){
}
publicboolean test(){
try{
System.out.println("Linea 1");
mHttpConnection = (HttpConnection)Connector.open("http://www.google.com");
System.out.println("Linea 2");
din = mHttpConnection.openDataInputStream();
System.out.println("Linea 3");
int input;
stResponse="";
while ( ((input = din.read()) != -1) && (stResponse.length()<1) ){
stResponse += (char) input;
}
if (stResponse.length()>0){
bTestOK=true;
}
}catch (IOException ioe){
System.out.println("Exception: "+ioe);
}
return bTestOK;
}
}
Message was edited by:
ruvyo
[3910 byte] By [
ruvyoa] at [2007-11-27 5:16:06]

# 1
Network methods are blocking calls so they may cause your S60 to hang until they return. Have you tried calling it from its own thread?
public class TestConnection extends Thread {
/**instance to stablish the HTTP connection*/
private HttpConnection mHttpConnection=null;
/**variable to indicate if the program is cancelled*/
private boolean bTestOK=false;
/**output stream to server*/
private DataOutputStream dout = null;
/**output stream from server*/
private DataInputStream din = null;
/**Response from server*/
public String stResponse="";
/** Creates a new instance of TestConnection */
public TestConnection() {
start();
}
public void run() {
try {
System.out.println("Linea 1");
mHttpConnection = (HttpConnection)Connector.open("http://www.google.com");
System.out.println("Linea 2");
din = mHttpConnection.openDataInputStream();
System.out.println("Linea 3");
int input;
stResponse="";
while ( ((input = din.read()) != -1) && (stResponse.length()<1) ) {
stResponse += (char) input;
}
if (stResponse.length()>0) {
bTestOK=true;
}
} catch (IOException ioe) {
System.out.println("Exception: "+ioe);
}
}
}
# 2
I haven't tryied it, but in my application is important not to continue running if there's no connection. Now, after changing another parts of the code 1000 times, seems to make the "TestConnection" correctly on the device (Nokia 6630). However, later in the code, the connection doesn't works... why? I don't know... But in emulator still not works anything, so the debug is going to be funny :s
I have read on release notes of the emulator, but doesn' works :'( :
Connectivity
- In some environments Ethernet Support fails to initialize correctly.
Workaround: Start npacket service manually. The detailed steps are as
follows:
-- Assumption: ethernet support is configured using configuration UI
-- in Emulator -> Tools -> Preferences -> Ethernet Settings
1. Start emulator
2. Start Browser (or another application using TCP/IP)
3. Start application called npacketadmin.exe from
\<SDK_Installation>\Epoc32\tools
4. From npacketadmin UI select the network adapter you are
using for TCP/IP connectivity.
5. Check the status. Correct state should be "STARTED", when emulator
is running.
6. If status is "STOPPED", close the emulator.
7. After emulator has been shut down. Select "Start" button.
8. When status has changed to "STARTED", restart emulator.
9. Test that browser functions normally.
- E-Mail application does not support DNS resolving. Hence, e-mail
server address must be given as a numeric IP address. Using
symbolic names is not possible.
- Ethernet support feature can't be used with WLAN connection
- Ethernet support does not support https.
- If SDK installation path contains spaces it is not possible to browse
to a web page .
ruvyoa at 2007-7-12 10:38:34 >
