-
Notifications
You must be signed in to change notification settings - Fork 43
Developer Journal
Maciej Wasilak edited this page Jan 13, 2014
·
2 revisions
This page is meant for collecting some important bits of knowledge, that do not fit anywhere else.
Twisted UDP currently doesn't support IPv6 for UDP communications. There is a ticket for that, and most probably Twisted 14.0 will have official support. But for now a hack is needed:
In twisted/Twisted-13.x.x/twisted/internet/udp.py :
def __init__(self, port, proto, interface='', maxPacketSize=8192, reactor=None):
"""
Initialize with a numeric port to listen on.
"""
base.BasePort.__init__(self, reactor)
self.port = port
self.protocol = proto
self.maxPacketSize = maxPacketSize
self.interface = interface
self.setLogStr()
self._connectedAddr = None
+ if interface and abstract.isIPv6Address(interface): ###
+ self.addressFamily = socket.AF_INET6 ###
and
def doRead(self):
"""
Called when my socket is ready for reading.
"""
read = 0
while read < self.maxThroughput:
try:
data, addr = self.socket.recvfrom(self.maxPacketSize)
except socket.error as se:
no = se.args[0]
if no in _sockErrReadIgnore:
return
if no in _sockErrReadRefuse:
if self._connectedAddr:
self.protocol.connectionRefused()
return
raise
else:
read += len(data)
try:
+ addr = (addr[0], addr[1]) ###
self.protocol.datagramReceived(data, addr)
except:
log.err()
This allows for simple unicast UDP communication. Works on Windows, Linux and Android.