[Twisted-Python] twisted and gprs

Phil Mayers p.mayers at imperial.ac.uk
Mon Jan 8 13:21:42 MST 2007

John Aherne wrote:
> Thanks to Phil, Carl and JPCalderone for the replies.
> I'll try and answer them by explaining more clearly what I am trying to 
> do. And explaining some terms that I were vague.
> The sessions are a connection that I need to keep open -  a combination 
> of IP address and source port no - so the server can use the source port 
> number that the PDA used when making the initial connection. The PDA 

You only need to do this with UDP or other connection-less protocols. 
TCP will bind the connection and do the tracking for you.

> will need to block on the TCPIP socket waiting for messages to be sent 
> to it. It will process the message and then wait again. Provided the PDA 
> does not close the socket and lose the connection with the original port 
> no, the firewall will let the conversation keep going.

You will need keepalives for this, but yes.

> The server will send on the initial source/destination port nos and not 

Again, TCP does this automatically

> close the connection. This way the PDA can still be contacted over a 
> long period of time. Because the PDA is behind the network firewall, if 
> the original port used by the PDA is lost, the server can no longer send 
> data to the PDA, since the firewall will not let the traffic through 
> even though the IP address had not changed.
> As Carl pointed out I will need more than the IP address to identify the 
> PDA. I will need an ID from the PDA that is unique so that if the PDA 
> comes back in with a different IP address I can pick that up, drop the 
> existing IP/port no if I still have it and register it with it's new IP 
> address and source port no.
> As i write this down, explaining it to myself as much as anyone else, I 
> think to myself that the mechanics look very much like an irc 
> connection. I might be wrong so please let me know.

I don't know why you're bringing up IRC. IRC uses TCP, so no port-number 
bookkeeping will be required.

> The server will need to ping the PDA to confirm the connection is still 

Again, TCP keepalives

> there. If lost it will deregister the PDA and wait for it to reconnect 
> again. What I am not sure about with irc is whether I can keep hold of 
> the port no used by the PDA as its source port and maintain the 
> connection with the IP address/port no combination.

Again, IRC uses TCP which does this all automatically. Forget about the 
port numbers.

> What I would like is if I can find a framework that does most of the 
> heavy work with the communications. I can then find a suitable point to 
> make some not too difficult changes to accommodate my requirements.
> I have done a very simple test using the socket library to confirm that 
> the basics do work. The connection stays open and as long as I do not 
> close the socket connection at either end and use the same 
> source/destination port numbers the traffic flows.And I can push data 
> without the PDA having to initiate new connections and requesting data.
> I hope this a better explanation than my first post. I am sure there 
> will still be bits that might not be clear so let me know and I will 
> fill in any gaps.
> If it is clear,  what I am looking to find out is which bits of twisted 
> I would need to use and what parts would need changing and to what extent.
> One final note, there could be around 100 of the PDAs to look after.

That's a tiny number.

Just have each PDA make a TCP connection to the server. Enable TCP 
keepalives on both the client and on the server ends of the connection. 
Have the first operation on a new TCP connection be a "login" i.e. PDA 
says here is my ID, server maps the ID to a TCP connection. Have your 
server message distribution look up the current TCP connection for a 
given ID and send the message.

It's a trivial application.

More information about the Twisted-Python mailing list