Persistent GPRS Connection

Denis Aherne

New Member
Licensed User
Longtime User
This is my First Post to the forum.

I have been playing around with the Basi4Android,- which I think is a fine product - to see how things work and what I might use to solve a problem.

The problem I am working on is this:

I need a permanently connected GPRS connection so I can send randomly timed messages to android devices.

To keep the connection open,I send keepalive mesages from the android.
The problem occurs when I do not get an acknowledgment back within
30 secs - the timeframe for deciding the connection is broken.

To check for the 30 second timeframe I start a startserviceAT

At the moment I put the message IDs in a list and when the service fires
after about 30 seconds, I assume I am working with the first one in the list


What would be nice is if I could pass a parameter with the startserviceAT command to say which message ID I am working with. So that when it fires in 30 seconds I have the ID that will have failed, rather than making an assumption.

I could probably make the assumption valid but it would be good just to have the ID ready to hand.


So far I have not found a way of doing this.

So my question is:

Have I gone about this completeley the wrong way..
Or have I overlooked some obvious method of making a deferred call and passing a parameter

So I am wondering if anyone can give me some pointers to a better way of solving the problem

Some further background for anyone that may not already know this:--

The nature of GPRS is that the connection could disappear at any time and be
reconnected at any time.

However, the mobile network routers along the way will not immediately drop
the connection on the basis that GPRS will always be dropping and reconnecting.

So they will keep the connection up for a determined period of time. Some will do 15 mins,others 30, others 1/2 mins.

When GPRS reconnects it could come back with the same connection.

If the router has really dropped the connection then a new connection will have to be made

So the only way I have of telling if a connection is down is to send an acknowledgment back for every keepalive message sent from the android.

Thanks for any help or info

Regards

John Aherne
 

thedesolatesoul

Expert
Licensed User
Longtime User
Sounds interesting...I am not sure if I understand this fully...
So when you send a keepalive message, why do you not keep track of the acknowledgements you receive? Isnt that the only way you can be sure that your message ids are valid?
You could use Timers instead of the service (not sure if that makes much difference).
 
Upvote 0

Denis Aherne

New Member
Licensed User
Longtime User
Thanks for the reply.

Keeping track or message ids when I get a response is the easy bit. Since the response will contain the message id. And I can pop the stored message. And carry on

The problem is I send a message with an id and do not get a response back. So in my list of sent message ids I have to assume that it is the first one in the list.

I would rather be a bit surer which id I am working with.

I have looked at timers. But I think they may be killed off if I hang around waiting for up to 30 seconds. I have not tried it but from looking through the forum that was the impression I got.

The safest way seemed to be a one-shot startserviceAT.

But that doesn't let me pass a parameter

And if the 30 second timer fires, I will need to drop the connection and start it up all over again to be sure I am connected.

Thanks

John
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I think you are maybe overcomplicating things a bit, but i cant be sure what your operating conditions are.
Here is an idea...at any given time you will only have 'n' outstanding acknowledgements remaining.
If you create an array or list of 'countdown timers' (not b4a ones) for each message id...use a timer object to decrement all of these timers every 1 second, and if one of them hits zero, you will know which timer hits zero first and times out.
 
Upvote 0

Denis Aherne

New Member
Licensed User
Longtime User
Thanks for the reply.

I think what you suggest is what I can currently do.

In effect I set a startserviceAT whenever I send a message and I put the message id into a list.

If I get a reply I pop the message id from the list since I will know the message id from the response.

If I do not get a reply after 30 secs, the service fires and it will take the top one from the list.

In theory, the top item in the list will always be the message that failed, since it will be the longest outstanding.

However, it would be preferable to have the id available of the message that fails, instead of effectively guessing.

I know the message id when I send the message and when I create the 30 second startserviceAT. If I could pass the message id as a parameter to the starserviceAT or a timer that would probably do the trick. Or some other way of doing things that would achieve the same ends.

.
Regards

John
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
In theory, the top item in the list will always be the message that failed, since it will be the longest outstanding.
I think that should be in practice as well.
Is there a case you can think of where the top item will not be the message that failed? After all the timeouts will have to happen in sequence, it is all time dependent.
How can a later message time out before the first message?

Also, you are storing the message ids in the list? So you will always know that.

Communication b/w activities and services is usually done with Public variables. I dont think you can pass parameters to it.
A service is not an instance of an object so it will not retain state in the way you want to.
 
Last edited:
Upvote 0
Top