|
Post by kallin on Feb 1, 2009 15:13:02 GMT -5
Hey everyone,
I'm trying to do some basic socket programming in J2ME. I've managed to have a j2me emulator connect to my j2se server using the standard Connector class, but when I try to run this JAD on my phone (motorola W385) it says
"Test MIDlet isn't reacting. Maybe it's just slow. You can kill it or keep waiting."
Then it dies out with a nullpointerexception.
I have the port (9876) open on my router forwarding the right computer, and it works just fine with the emulator. I'm not sure if it's a problem with the phone, or maybe with my provider (Telus).. I did notice that the games of Adam's I download do successfully make connections to download the ads, so I'm perplexed...
Could anyone offer some suggestions as to what's going on? This is very confusing..
Thanks! Kal.
|
|
|
Post by kallin on Feb 1, 2009 15:19:34 GMT -5
I read something interesting here: www.wirelessdevnet.com/channels/java/features/j2me_http.phtml"I tested the socket, datagrams, and http connections with MotoSDK (a development kit from Motorola). All three types of connections are supported by the Motorola’s MIDP. Sun’s MIDP reference implementation supports only the http connections." I've been using the reference sun sdk, so maybe that's a problem if i want to do something other than http?? I'll try using the motorola sdk, and maybe http with sun as well and see what happens..
|
|
|
Post by Adam Schmelzle on Feb 1, 2009 17:57:42 GMT -5
I'm pretty sure that my moto doesn't like sockets at all, but doesn't lock up. Much depends on the device though. If motorola has a special library that they suggest, it would definitely be worth trying.
Have you had the same problems using a PC to connect to your socket server from outside of your network?
"null pointer exception and 'not responding'": sounds like there should be a better way to determine if sockets are available on device before it crashes on you. What type of detection do you do before trying to use the connection?
You should always do something like this to at least check that the Socket class is available before attempting to use it...
try { Class.forName("javax.microedition.io.SocketConnection"); System.out.println("socket class is available"); return; } catch (Exception e) { netStreamGrabber = null; System.out.println("socket class NOT available"); }
|
|
|
Post by kallin on Feb 1, 2009 19:47:11 GMT -5
I have no problems getting a PC to connect to my server. I found out that switching from
SocketConnection hc = (SocketConnection ) Connector.open("socket://blah:1234");
to
HttpConnection hc = (HttpConnection) Connector.open("http://blah:80");
works.
Also I can do Class.forName("javax.microedition.io.SocketConnection") without issue, so the class is there...
|
|
|
Post by kallin on Feb 1, 2009 20:10:36 GMT -5
I'm planning on getting one of the new RazrVE20's for a school project and I need to be able to do TCP and UDP on it. We're basically using it as a 3G conduit in order to stream controls to a car (via microcontroller hooked up to the phone through USB) and send back some sensor data (video/audio/etc).
Do you think that a new phone like that would have the same socket issues? If so, could you suggest another one?
Thanks, Kal.
|
|
|
Post by kallin on Feb 1, 2009 20:16:23 GMT -5
|
|
|
Post by Adam Schmelzle on Feb 1, 2009 20:16:26 GMT -5
Unfortunately there's no guarantee. Some devices may have problems because of permissions even if sockets and UDP are supported. You could probably hack the device to get rid of the permission errors if they exist.
I haven't played with it much yet, but it's probably a safe bet that the google developer phone has all the networking unlocked. If you are required to make a MIDP app then it's a problem, but otherwise it's got more of the J2SE library available than a standard phone.
|
|