×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Sep 2007
    Location
    Barranquilla - Colombia
    Posts
    38

    Question Sending/Receiving data to server in background

    Greetings!
    i have developed a mobile app, this mobile app works with the internal storage ( rms ). But, in addition, i need the application to do something like this ( in human language ):

    "every N minutes, the internal data must be sent to a web server in order to update some tables in a database located on this web server."

    I would like to achieve this with no human intervention ( in other words, a background task must be launched every N minutes while the mobile app is executing )

    How can i achieve this?

    Some remarks:
    -) I'm using HttpConnection in order to communicate the mobile app with the server, and it's working fine.

    -) I'm working with Netbeans IDE 6.7.1, platform S40 5th edition.

    Thanx in advance,

  2. #2
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    62

    Re: Sending/Receiving data to server in background

    I would like to achieve this with no human intervention ( in other words, a background task must be launched every N minutes while the mobile app is executing )

    How can i achieve this?
    With the help Push Registry you can activate midlet as you required.
    To read more about the Push Registry go for the given link and if you search you will find more good tutorial realted to Push Registry.

    http://developers.sun.com/mobility/m...icles/pushreg/

    Hope this information will help you.

    Thanks
    Avdhesh

  3. #3
    Registered User
    Join Date
    Sep 2007
    Location
    Barranquilla - Colombia
    Posts
    38

    Re: Sending/Receiving data to server in background

    Thanx Avdhesh for your kind reply.
    I will take a look @ this approach.

    Best regards,

  4. #4
    Registered User
    Join Date
    Sep 2007
    Location
    Barranquilla - Colombia
    Posts
    38

    Re: Sending/Receiving data to server in background

    Hi Avdhesh
    i followed the URL http://developers.sun.com/mobility/m...icles/pushreg/
    and i was testing with the TimerTask class. It seems to work exactly as i thought it would be ( "every N minutes a task is launched"), but when i add my method to send data via HttpConnection in the scheduled task, it does not invoke ....Is there some restriction for the methods the TimeTask class can use?

    This is the piece of code i use to send|receive data to|from the server:

    public String getViaStreamConnection(String url) throws IOException {

    StreamConnection streamConnection = null;
    InputStream inputStream = null;
    StringBuffer b = new StringBuffer();

    try {
    streamConnection = (StreamConnection)Connector.open(url); <== from here goes to the "finally" block when i debug this part
    inputStream = streamConnection.openInputStream();
    int ch;

    while((ch = inputStream.read()) != -1) {
    b.append((char) ch);
    }

    } finally {

    if (inputStream != null) {
    inputStream.close();
    }
    if(streamConnection != null) {
    streamConnection.close();
    }
    }

    return b.toString();

    }




    PS: first of all ... my method to send data via HttpConnection is working fine, because this method sends/receives data to/from the server, when it is invoked out of the scheduled task.

    Thanx in advance ... and sorry for my bad english =0)

  5. #5
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    62

    Re: Sending/Receiving data to server in background

    Hi,

    As u said the timer task functionality is working when you do normal thinks.But it's not work when send the data with the help of HttpConnection.
    I guess whn you open the HttpConnection your device asked the permission to connected the network. This seem to be a problem. You go for the device setting and set the network permission always allowed.
    Hope it will work..

    Thanks
    Avdhesh

  6. #6
    Registered User
    Join Date
    Sep 2007
    Location
    Barranquilla - Colombia
    Posts
    38

    Re: Sending/Receiving data to server in background

    Hi Avdhesh
    I found the solution to the problem with the HttpConnection calling ... for some reason ( i think it was some variables with null values ) the URL was malformed. So:
    1) i assigned them a default value
    2) i encoded each value sent in the URL, something like this
    myURL = myURL + "?parm1=" + objUtilities.encodeURL(parm1_value);
    myURL = myURL + "?parm2=" + objUtilities.encodeURL(parm2_value);
    myURL = myURL + "?parm3=" + objUtilities.encodeURL(parm3_value);
    ...and so on.
    ( objUtilities is an instance of a class named "utilities" that I use in my MIDlet )

    Once the URL was "well-formed" , the data sending via HttpConnection worked fine and I'm happy =0)

    This is the code I used to encode the values:


    public String URLencode(String s)
    {
    if (s!=null) {
    StringBuffer tmp = new StringBuffer();
    int i=0;
    try {
    while (true) {
    int b = (int)s.charAt(i++);
    if ((b>=0x30 && b<=0x39) || (b>=0x41 && b<=0x5A) || (b>=0x61 && b<=0x7A)) {
    tmp.append((char)b);
    }
    else {
    tmp.append("%");
    if (b <= 0xf) tmp.append("0");
    tmp.append(Integer.toHexString(b));
    }
    }
    }
    catch (Exception e) {}
    return tmp.toString();
    }
    return null;
    }

  7. #7
    Registered User
    Join Date
    Sep 2007
    Location
    Barranquilla - Colombia
    Posts
    38

    Smile Re: Sending/Receiving data to server in background

    Quote Originally Posted by coolavdhesh View Post
    Hi,
    I guess when you open the HttpConnection your device asked the permission to connected the network. This seem to be a problem. You go for the device setting and set the network permission always allowed.
    OK, the device asked me for permission to connect to the network each time the device tries to establish the communication. I press "OK" and that's all, the communication is established and the data is sent.

    That's ok for me by now, because i'm in a development stage. I suggested to my boss to buy a verisign certificate in order to avoid this behaviour during the "go-live" stage ( the user won't have to authorize the connection .... that's not his prerrogative =0)

    Very thank you to take your time for replying my posts.

Similar Threads

  1. KERN-EXEC 3 or 0 with GPS sample code
    By neil.young in forum Symbian
    Replies: 12
    Last Post: 2009-10-14, 20:50
  2. Replies: 0
    Last Post: 2009-05-31, 13:08
  3. GPRS connection problems on 6600..
    By suckho in forum Symbian Networking & Messaging (Closed)
    Replies: 10
    Last Post: 2005-12-02, 14:00
  4. Replies: 2
    Last Post: 2004-09-15, 22:47

Posting Permissions

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