[英]twisted connectTCP with IPv6
How can I access an IPv6 address with twisted and listenTCP?如何使用 twisted 和 listenTCP 访问 IPv6 地址? If I take the address from ifconfig, with eg aaa::bbbb:cccc:dddd:eeee then I get the following error message:
如果我从 ifconfig 中获取地址,例如 aaa::bbbb:cccc:dddd:eeee,则会收到以下错误消息:
raise CannotListenError(self.interface, self.port, le) twisted.internet.error.CannotListenError: Couldn't listen on aaa::bbbb:cccc:dddd:eeee
Either endpoints.serverFromString
that specify an IPv6 interface value or explicitly call endpoints.TCP6ServerEndpoint
. endpoints.serverFromString
指定 IPv6 接口值或显式调用endpoints.TCP6ServerEndpoint
。
from twisted.internet import endpoints, protocol, reactor
class Echo(protocol.Protocol):
def connectionMade(self):
print(f"{type(self.transport)}")
def dataReceived(self, data):
self.transport.write(data)
# Use one of the following
# Server string, note the backslashes
tcp6 = endpoints.serverFromString(reactor, "tcp:8000:interface=\:\:1")
# Or explicit IPv6 endpoint
tcp6 = endpoints.TCP6ServerEndpoint(reactor, 8000, interface="::1")
factory = protocol.Factory.forProtocol(Echo)
tcp6.listen(factory)
reactor.run()
If that doesn't work, then you might need to make sure IPv6 is enabled on your system.如果这不起作用,那么您可能需要确保在您的系统上启用了 IPv6。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.