×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Mar 2003
    Location
    South Africa
    Posts
    10

    J2ME and Server communication

    Hallo all
    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?

  2. #2
    Registered User
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    15
    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.

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    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.

    Graham.

  4. #4
    Registered User
    Join Date
    Jun 2004
    Location
    Sydney
    Posts
    3

    polling costs

    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...?

  5. #5
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    If you look at the http specification, you'll see that even an empty response has http headers so it's not really empty.

    shmoove

  6. #6
    Registered User
    Join Date
    Jun 2004
    Location
    Sydney
    Posts
    3

    polling servlets

    a http header is attached by the webserver as the document is being sent out - which means there will always be unavoidable overhead when requesting a .html file.

    but

    when a jServlet handles a httpRequest does the webserver also automatically attach the usual headers when it sends the response?

    how can I send a zero sized http response? [I know that sounds illogical and impossible but there must be a way] I want to be able to poll without having to pay for every blank response

  7. #7
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    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.

    shmoove

  8. #8
    Registered User
    Join Date
    Jun 2004
    Location
    Sydney
    Posts
    3

    polling without paying

    hmmm...

    perhaps that could work.

    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?
    Last edited by kahne; 2004-07-07 at 00:35.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×