Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Windows Python 2.5.1 IPV6 problems (http://www.velocityreviews.com/forums/t589147-windows-python-2-5-1-ipv6-problems.html)

Thomas DiZoglio 02-03-2008 05:05 AM

Windows Python 2.5.1 IPV6 problems
 
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/browse...xarkun/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

Martin v. L÷wis 02-03-2008 07:48 AM

Re: Windows Python 2.5.1 IPV6 problems
 
> _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


All times are GMT. The time now is 07:37 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.