views:

741

answers:

4

Can a J2ME app be triggered by a message from a remote web server. I want to perform a task at the client mobile phone as soon as the J2ME app running on it receives this message. I have read of HTTP connection, however what I understand about it is a client based protocol and the server will only reply to client requests. Any idea if there is any protocol where the server can send a command to the client without client initiating any request?. How about Socket/Stream based(TCP) or UDP interfaces?.

+2  A: 

If the mobile device doesnt allow you to make TCP connections, and you are limited to HTTP requests, then you're looking at implementing "long polling".

One POST a http request and the web-server will wait as long time as possible (before things time out) to answer. If something arrives while the connection is idling it can receive it directly, if something arrives between long-polling requests it is queued until a request comes in.

If you can make TCP connections, then just set up a connection and let it stay idle. I have icq and irc applications that essentially just sit there waiting for the server to send it something.

Christian
I've read that MIDP2.0 has support for TCP/UDP conncections in addition to HTTP. And with tcp we would try to open a connection with the server usingConnector.open("socket://ip:port")where ip:port are ip address and port respectively of the server.If tried this code however a connection is not formed with the server at port 80. It says port not allowed for unknown connections.Any ideas!
Kevin Boyd
In fact the error message says"Target port denied to untrusted applications" I dont know how to get over this error
Kevin Boyd
+2  A: 

You should see PushRegistry feature where you can send out an SMS to a specific number have the application started when the phone receives that SMS and then make the required HTTP connection or whatever. However, the downside of it is that you might have to sign the application to have it working on devices and you also need an SMS aggregator like SMSLib or Kannel

Ram
I have gone into the PushRegistry feature and SMS was one of the options, however if a socket or HTTP connection can suffice I would rather move in that direction. It seems that pushregistry also supports network connections, I just want to play around with these till I close in on my options.
Kevin Boyd
+1  A: 

Socket push are supported by j2me. But it could work only if your server could deliver data to your mobile phone. Most likely that operator gateway don't allow to do this. Maybe it would be possible if your mobile has static external IP address - some operators could provide this for $$.

Pavel Alexeev
I think after reading all the answers, HTTP connection and long poll are the way to go, there is a lot a ambiguity on socket push and I dont know how many service providers do allow inbound connections to phones probably they block them.I hope I am proved wrong with a better answer.
Kevin Boyd
+2  A: 

You can open socket connection and implement "Hide" (or "Minimize") functionality in your app. Call this to hide:

Display.getDisplay(MyMIDlet.instance).setCurrent(null);

Listen to the server in a loop, and if you receive some message, popup the applicaion by calling this from canvas:

Display.getDisplay(MyMIDlet.instance).setCurrent(this);

But it dosen't work on all devices.

Pavel Alexeev
As per your previous post, socket connection is not support by all phone isp's and they might block incoming connections to the phone. How about opening up an HTTP connection, but frequent polling to the server might be heavy on the users pockets as GPRS billing is traffic based, any way out of this.
Kevin Boyd
No, socket connection is supported, PushRegistry using sockets in not, because in this case server need to push data directly to mobile device. <br>But when you open socket connection and *leave it open*, everything should work fine - I've tried it myself, and some applications (like GMail for j2me) use it.
Pavel Alexeev