IPv6 and Python

Roy Smith roy at panix.com
Fri May 2 23:38:39 EDT 2008


In article 
<80747335-9d08-48c9-bcc6-e66b6f2ef656 at l42g2000hsc.googlegroups.com>,
 "Giampaolo Rodola'" <gnewsg at gmail.com> wrote:

> Thanks a lot. I've been able to listen on ::1:21 after having
> installed IPv6 on both Windows and Linux thanks to your suggestions.
> I'd like to ask one more question: is it possible to bind my server on
> both IPv4 and IPv6 addresses (note: I do not use multiple threads or
> processes)?

In theory, you should be able to bind your server socket to an IPv6 port 
and have it accept connections from both IPv4 and IPV6 clients.  The v4 
connections will show up as IPv4-mapped IPv6 addresses (i.e. with a 
::ffff/96 prefix).  In practice, support for this is spotty.  The Wikipedia 
IPv4_mapped_address article claims, for example, that no windows OS prior 
to vista supports it.

In the application I work on, we've avoided this.  We just listen on two 
separate sockets (one for each address family).  We wrote a DualSocket 
class which manages the two underlying single-protocol sockets and makes 
them appear to be a single dual-protocol socket.  It was a lot of user code 
to write, compared with using the mapped address mechanism, but at least 
it's portable to every OS we've seen that support IPv6.

You don't need multi-threading to handle multiple sockets.  In our 
implementation, for example, we use select() in a single thread to 
multiplex the two.



More information about the Python-list mailing list