if you want only ipv4, then you may just bind your socket explicitly
to an ipv4 address instead of the `localhost' host name.
for example,
socket.bind("127.0.0.1", port)
will bind to the ipv4 address of the loopback interface, while
socket.bind("192.168.XXX.XXX", port)
or some address similar will bind to the specified interface. and
socket.bind("0.0.0.0", port)
will bind to ipv4 addresses of every configured interface.
to explicitly bind to ipv6 address, use an ipv6 address instead. for
example, "::1" is the ipv6 address of the loopback interface.