I want to develop a J2ME application that connects to a server and waits for data from the server. I know that this can be done the following way:
The application connects to the server and polls the server every second for new data. BUT doing this will cost a lot of money in South Africa. GPRS is really expensive. So, I would like to know if it will be possible for the J2ME application to connect to a server and the server will then send information to the application without the application polling the server for it. A socket connection would be perfect for this but can you make a socket connection using the 6610? I will use a 6610 to do my development on.
So basically I want to develop a J2ME application that will connect to a server and the server will send data to the application without the application polling for the data. This will limit the data flow over the GPRS connection and this will minimize the cost.
Is this possible or does anybody have any suggestions?
I guess that it can be done with httpconnection, just make sure that you send back proper http-response from server. So, connect to server via http-connection, then open the inputStream in your midlet (opening inputstream reads the response-header, so make sure you send it before the actual data from your server). Then read all the incoming bytes until you reach -1, which means the connection has been closed from server.
You cannot open a socket connection on a 6610. You could try an HttpConnection as sampoy suggests, but I suspect that the connection will be terminated if there is no activity for more than a minute or so (that is, the connection will time-out). You would need to test this. Also, how long the connection will stay open may be phone and/or network dependent.
If you use polling... you are unlikely to be able to poll every second, due to the network delays involved in a WAP-based connection. Typical round-trip times for a single request-response transaction may be on the order of several seconds.
Wanting to make polling efficient - there is a way.
Would it be possible to:
- make the httpConnection
- send the request
- and then if the server doesn't need to send a reply it simply sends a zero length ;empty' response - as GPRS is charged per bit this will not cost anything, basically making the polling process free...
Does this work or does this zero length 'empty' response contain overhead that telco's charge for...?
You can't. If you did it wouldn't be a valid http request, and the HttpConnection object would freak (you would probably get some kind of "malformed response" message). Those headers are part of the http specification, without them it won't be http.
if the server responded with a 'malformed response' that would be enough. The client could simply catch that error (exception) and assume that the server responded with something useless - meaning: there have been no updates...
Perhaps another way could be that the server simply doesn't respond to requests if there have been no updates and so lets it time-out.
QUESTION: Generally telco's (optus - Australia) charge approx 2c per kbyte downloaded and a approx 20c flagfall to connect grps. Is there a minimal charge for each httpRequest as well, if a httpRequest is sent and nothing is returned are there any charges for that event?