I'm trying to get a Java MIDlet to open a connection with a server on
another machine. But I'm getting a ConnectionNotFoundException thrown.
I've googled the web and Sun's site every which way I can looking for
the answer to a similar experience somebody else may have had, but not
found a solution. So I'd like to present the question here in the hope
that somebody might be able to help. Specifically, I'm looking for a
short MIDlet subclass implementation (similar in previty to the code
I've enclosed below) that doesn't throw an exception and that returns
a valid response code from a server running on another machine. The
code should run using the configuration described below or an
explanation for why my configuration will never work should be
included in the answer.
Here's the configuration I'm using...
* I'm developing using NetBeans 3.6 on Win2K Pro.
* I'm using WTK2.1 as downloaded from Sun's web site.
* The MIDlet is configured as CLDC 1.1, MIDP 2.0 with the Wireless
Messaging, Mobile Media and J2ME Web Services optional libraries
selected.
* I've gotten the same behavior with no MIDlet permissions specified
in the jad and with virtually all combinations of the following
permissions...
javax.microedition.io.Connector.comm
javax.microedition.io.Connector.http
javax.microedition.io.Connector.https
javax.microedition.io.Connector.socket
javax.microedition.io.Connector.ssl
* I've run the wireless toolkit network monitor, but no activity shows up.
* The debug machine I'm testing this on is on the same subnet as the
server I'm trying to connect to and neither machine has any kind of IP
filters or firewall enabled.
* The server is definiately running on the machine having address
192.168.0.102. and the server has a listen waiting on port 9700 of
that machine.
I've tried to distill the problem down as much as I can. And in so
doing I'm left with this...
import javax.microedition.midlet.*;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
public class MyMidlet extends MIDlet implements CommandListener {
public MyMidlet() {
System.out.println("Midlet constructor called.");
try {
int code;
HttpConnection conn = (HttpConnection)Connector.open(
"http://192.168.0.102:9700/unknown-unknown?0,-1,http://192.168.0.102:9700/EndpointService:jxta-NetGroup/uuid-DEADBEEFDEAFBABAFEEDBABE0000000F05/pid",
Connector.READ_WRITE);
conn.setRequestMethod(HttpConnection.GET);
conn.setRequestProperty("Connection", "close");
conn.setRequestProperty("Content-Length", "0");
code = conn.getResponseCode(); // Throws exception
}
catch (Exception e) {
System.out.println("getResponseCode() failed: " + e + ".");
e.printStackTrace();
}
}
public void startApp() {
}
public void pauseApp() {
}
public void destroyApp(boolean aUnconditional) {
}
public void commandAction(Command aCmd, Displayable aDisplayable) {
}
}
Here's the output from the i/o pane of the MIDlet...
c:\WTK21\bin\emulator -Xdebug
-Xrunjdwp:transport=dt_socket,address=5500,server=y
-Xdevice:DefaultColorPhone
-Xdescriptor:"Z:\Projects\Project\MyProject.jad"
Connecting to 127.0.0.1 on port 2800
Waiting for debugger on port 5500
KVM not ready
Running with storage root DefaultColorPhone
Connection received.
Midlet constructor called.
getResponseCode() failed:
javax.microedition.io.ConnectionNotFoundException: TCP open.
javax.microedition.io.ConnectionNotFoundException: TCP open
at com.sun.midp.io.j2me.socket.Protocol.connect(+99)
at com.sun.midp.io.ConnectionBaseAdapter.openPrim(+52)
at com.sun.midp.io.j2me.socket.Protocol.openPrim(+108)
at com.sun.midp.io.ConnectionBaseAdapter.openPrim(+14)
at com.sun.midp.io.ConnectionBaseAdapter.openPrim(+8)
at com.sun.midp.io.j2me.http.Protocol.connect(+73)
at com.sun.midp.io.j2me.http.Protocol.streamConnect(+57)
at com.sun.midp.io.j2me.http.Protocol.startRequest(+12)
at com.sun.midp.io.j2me.http.Protocol.sendRequest(+38)
at com.sun.midp.io.j2me.http.Protocol.sendRequest(+6)
at com.sun.midp.io.j2me.http.Protocol.getResponseCode(+8)
at com.momentiv.midp.MyMidlet.<init>(+56)
at java.lang.Class.runCustomCode(+0)
at com.sun.midp.midlet.MIDletState.createMIDlet(+19)
at com.sun.midp.midlet.Selector.run(+22)
When I googled around the net I seen that others have experienced the
same exception. But none of the postings about this issue have ever
gotten a useful response beyond, "make sure the workstation you're
debugging on is connected to the internet and that the machine it is
trying to connect to is not on the other side of a firewall."
Any help is greatly appreciated.
Sparky |