[Twisted-Python] twisted and gprs networks
srock258 at gmail.com
Mon Jan 8 11:18:16 EST 2007
I have done some GPRS comms work with Python using asyncore and UDP sockets.
I'm in the process, if someone would give me a charge number, of moving to
Twisted as I am certain I can achieve the same goal in a much better design.
I had the same problem with the IP address of the client (the PDA in your
case). I used a polling design where each client routinely polled the
server. Every time a poll comes from a client I grab the IP and port form
the UDP header along with the client id embedded in the message. Saving this
in a dictionary gave me an easy to use lookup for pushing data out to the
client. You may need to get fancy with the dictionary. For example, I my add
a time stamp the record so I know the last time the client sent a response.
If a client has been down for some amount of time it could be removed the
So, you need:
1. Client has an id that it transmits with every message to the server
2. Client stores the server IP/PORT so it can poll independently.
3. RETRY LOGIC if you use UDP!!!
This has been deployed to the field server up to 3000 clients with a 25
second poll rate avg 22 bytes per message. In short, it works pretty well.
On 1/7/07, Jean-Paul Calderone <exarkun at divmod.com> wrote:
> On Sun, 07 Jan 2007 11:41:52 +0000, John Aherne <johna at johnaherne.co.uk>
> >I am looking at using PDA devices talking to a server over gprs.
> >I need to push data to the PDA over elapsed timeframes that might be
> >Naturally during this timespan the device may have been dropped from the
> >network or acquire a different IP address.
> >However to push data to the PDA, I need to record the IP and port used by
> >the PDA for its first contact since it is stuck behind a firewall.
> >The socket needs to be kept open on the PDA so the server can keep
> >responding on the same session over a period of time.
> >Using straight sockets I can do this by holding the reference to the
> >used by the PDA. And checking every now and then that the connection is
> >still valid. But I am no comms expert and I need to keep track of over
> >devices and keep reliably sending messages to them at random intervals.
> >So, I thought it might be better to use some framework for the server
> >I am no expert on sockets.
> >But looking through the docs for twisted and some of the code, I can't
> >anywhere how I can get and use a reference to the port and reuse the open
> >session on the PDA.
> >Can I do this with twisted or should I look for some other way of doing
> >I want.
> >I was thinking I could use irc with twisted but not sure if I am barking
> >the wrong tree.
> >Thanks for any ideas of solving the problem.
> It's not totally clear to me what you're after. Perhaps you could define
> some terms. What is a "session"? What kind of sockets are
> involved? What
> does it mean to "hold a reference" to an IP/port?
> If I try to guess at the answers to these questions, then it sounds like
> a pretty straightforward problem involving multiple connections, which is
> easily enough handled in Twisted.
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python