Windows Python 2.5.1 IPV6 problems

Discussion in 'Python' started by Thomas DiZoglio, Feb 3, 2008.

  1. Hi,

    I'm trying to get some IPV6 python code running under
    Windows. I have installed Python 2.5.1 for Windows
    using the binaries from python.org. I'm a newbie to
    Python programming as well.

    The code works fine under Debian and MacOSX (both
    using Python 2.5)

    I have rebuilt the python binaries from source and set
    ENABLE_IPV6. This didn't help. I have also read about
    not being able to bind to a IPV4 and IPV6 socket. I
    tried setting the setsockopt() call using IPV6_V6ONLY,
    but this is not recognized by the python interpreter.

    Thanks for any help I can get. I'm stuck on this and
    searching the NET for help.

    I get the following error:

    C:\test_py>python ipv6.py
    Traceback (most recent call last):
    File "ipv6.py", line 119, in <module>
    main()
    File "ipv6.py", line 113, in main
    p = listenTCP6(6666, TrivialServerFactory())
    File "ipv6.py", line 95, in listenTCP6
    return reactor.listenWith(Port, port, factory,
    backlog, interface)
    File
    "C:\python251\lib\site-packages\twisted\internet\posixbase.py",
    line 499,
    in listenWith
    p.startListening()
    File
    "C:\python251\lib\site-packages\twisted\internet\tcp.py",
    line 730, in st
    artListening
    skt = self.createInternetSocket()
    File
    "C:\python251\lib\site-packages\twisted\internet\tcp.py",
    line 718, in cr
    eateInternetSocket
    s = base.BasePort.createInternetSocket(self)
    File
    "C:\python251\lib\site-packages\twisted\internet\base.py",
    line 724, in c
    reateInternetSocket
    s = socket.socket(self.addressFamily,
    self.socketType)
    File "C:\Python251\lib\socket.py", line 154, in
    __init__
    _sock = _realsocket(family, type, proto)
    TypeError: an integer is required


    Thanks.
    -------------------------
    t0md

    I run with the following command:
    python ipv6.py

    ------------------------------------------------
    HERE IS THE CODE for ipv6.py:
    ------------------------------------------------

    #this is copied verbatim from
    http://twistedmatrix.com/trac/browser/sandbox/exarkun/ipv6.py
    #I'm unclear on the license that applies

    import socket
    from twisted.internet import tcp
    from twisted.internet import protocol
    from twisted.internet import reactor

    class IPv6Address(object):
    def __init__(self, type, host, port, flowInfo,
    scope):
    self.type = type
    self.host = host
    self.port = port
    self.flowInfo = flowInfo
    self.scope = scope

    def __eq__(self, other):
    if isinstance(other, IPv6Address):
    a = (self.type, self.host, self.port,
    self.flowInfo, self.scope)
    b = (other.type, other.host, other.port,
    other.flowInfo, other.scope)
    return a == b
    return False

    def __str__(self):
    return 'IPv6Address(%s, %r, %d, %d, %d)' % (
    self.type, self.host, self.port,
    self.flowInfo, self.scope)

    def isIPv6Address(ip):
    try:
    socket.inet_pton(socket.AF_INET6, ip)
    except:
    return 0
    return 1

    class Client(tcp.Client):
    addressFamily = socket.AF_INET6

    def resolveAddress(self):
    if isIPv6Address(self.addr[0]):
    self._setRealAddress(self.addr[0])
    else:

    reactor.resolve(self.addr[0]).addCallbacks(
    self._setRealAddress,
    self.failIfNotConnected
    )

    def getHost(self):
    return IPv6Address('TCP',
    *self.socket.getsockname())

    def getPeer(self):
    return IPv6Address('TCP',
    *self.socket.getpeername())


    class Connector(tcp.Connector):
    def _makeTransport(self):
    return Client(self.host, self.port,
    self.bindAddress, self, self.reactor)

    def getDestination(self):
    return IPv6Address('TCP', self.host,
    self.port, 0, 0)

    class Server(tcp.Server):
    def getHost(self):
    return IPv6Address('TCP',
    *self.socket.getsockname())

    def getPeer(self):
    return IPv6Address('TCP', *self.client)

    class Port(tcp.Port):
    addressFamily = socket.AF_INET6

    transport = Server

    def _buildAddr(self, address):
    return IPv6Address('TCP', *address)

    def getHost(self):
    return IPv6Address('TCP',
    *self.socket.getsockname())

    def getPeer(self):
    return IPv6Address('TCP',
    *self.socket.getpeername())

    def connectTCP6(host, port, factory, timeout=30,
    bindAddress=None, reactor=None):
    if reactor is None:
    from twisted.internet import reactor
    return reactor.connectWith(
    Connector, host, port, factory, timeout,
    bindAddress
    )


    def listenTCP6(port, factory, backlog=5,
    interface='::', reactor=None):
    if reactor is None:
    from twisted.internet import reactor
    #IPV6_V6ONLY = 27, IPV6_BINDV6ONLY
    #IPPROTO_IPV6 = 41
    #_socket.socket.setsockopt(_socket.IPPROTO_IPV6,
    _socket.IPV6_V6ONLY, 0)
    return reactor.listenWith(Port, port, factory,
    backlog, interface)

    def main():
    from twisted.internet import reactor

    class TrivialProtocol(protocol.Protocol):
    def connectionMade(self):
    print 'I (', self.transport.getHost(), ')
    am connected! (to ', self.transport.getPeer(), ')'
    self.transport.write('Hello, world!\n')

    def dataReceived(self, data):
    print 'Received: ' + repr(data)

    class
    TrivialServerFactory(protocol.ServerFactory):
    protocol = TrivialProtocol
    class
    TrivialClientFactory(protocol.ClientFactory):
    protocol = TrivialProtocol

    p = listenTCP6(6666, TrivialServerFactory())
    c = connectTCP6('::1', 6666,
    TrivialClientFactory())

    reactor.run()

    if __name__ == '__main__':
    main()


    CONFIDENTIALITY NOTICE: Proprietary/Confidential Information belonging to Virgil Software, Inc. may be contained in this message. If you are not a recipient indicated or intended in this message (or responsible for delivery of this message to such person), or you think for any reason that this message may have been addressed to you in error, you may not use or copy or deliver this message (and all attachments) to anyone else. In such case, you should destroy this message (and all attached documents) and are asked to notify the sender by reply email.


    ____________________________________________________________________________________
    Never miss a thing. Make Yahoo your home page.
    http://www.yahoo.com/r/hs
    Thomas DiZoglio, Feb 3, 2008
    #1
    1. Advertising

  2. > _sock = _realsocket(family, type, proto)
    > TypeError: an integer is required


    So what values have family, type, and proto at that point?
    Edit socket.py to find out.

    Could it be that you also need to set socketType for your
    Port subclass?

    Regards,
    Martin
    Martin v. Löwis, Feb 3, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,044
  2. Noah

    IPv6 Python on Windows

    Noah, Nov 8, 2003, in forum: Python
    Replies:
    1
    Views:
    327
    Martin v. =?iso-8859-15?q?L=F6wis?=
    Nov 8, 2003
  3. Philipp Hagemeister
    Replies:
    3
    Views:
    1,070
    Martin v. Löwis
    Mar 4, 2009
  4. Roedy Green

    Re: IPv6 in Java 6 +Windows possible?

    Roedy Green, Dec 2, 2010, in forum: Java
    Replies:
    1
    Views:
    527
    Arne Vajhøj
    Dec 2, 2010
  5. Jesse van den Kieboom

    Ipv6 on a ipv4/ipv6 hostname

    Jesse van den Kieboom, Jun 5, 2005, in forum: Ruby
    Replies:
    1
    Views:
    341
    Dibya Prakash
    Jun 5, 2005
Loading...

Share This Page