mwasilak / txThings

CoAP library for Twisted
94 stars 43 forks source link

IPv6 support #2

Closed erbdex closed 9 years ago

erbdex commented 9 years ago

Replacing the example with this- request.remote = ("aaaa::212:4b00:40e:f6e8", coap.COAP_PORT), i tried to make an IPv6 CoAP request. I am getting twisted.internet.error.InvalidAddressError which comes if I am either-

  1. Sending invalid ipv6 address.
  2. Twisted is expecting ipv4.

Is there a flag to specify that this one's IPv6? Stacktrace:

kafka@warbird ~/t/e/txThings> python examples/clientGET.py 2014-12-02 06:14:32+0530 [-] Log opened. 2014-12-02 06:14:32+0530 [-] Coap starting on 61616 2014-12-02 06:14:32+0530 [-] Starting protocol <txthings.coap.Coap instance at 0x7fea43b58998> 2014-12-02 06:14:33+0530 [-] Sending message to aaaa::212:4b00:40e:f6e8:5683 2014-12-02 06:14:33+0530 [-] Failed to fetch resource: 2014-12-02 06:14:33+0530 [-] [Failure instance: Traceback: <class 'twisted.internet.error.InvalidAddressError'>: 2014-12-02 06:14:33+0530 [-] /usr/local/lib/python2.7/dist-packages/Twisted-14.0.2-py2.7-linux-x86_64.egg/twisted/internet/base.py:824:runUntilCurrent 2014-12-02 06:14:33+0530 [-] examples/clientGET.py:47:requestResource 2014-12-02 06:14:33+0530 [-] build/bdist.linux-x86_64/egg/txthings/coap.py:921:request 2014-12-02 06:14:33+0530 [-] build/bdist.linux-x86_64/egg/txthings/coap.py:953:init 2014-12-02 06:14:33+0530 [-] --- --- 2014-12-02 06:14:33+0530 [-] build/bdist.linux-x86_64/egg/txthings/coap.py:988:sendRequest 2014-12-02 06:14:33+0530 [-] build/bdist.linux-x86_64/egg/txthings/coap.py:862:sendMessage 2014-12-02 06:14:33+0530 [-] /usr/local/lib/python2.7/dist-packages/Twisted-14.0.2-py2.7-linux-x86_64.egg/twisted/internet/udp.py:293:write

mwasilak commented 9 years ago

Twisted supports IPv6 literals for UDP since version 14.0.0. To send datagram to remote IPv6 address you have to specify local IPv6 when calling reactor.listenUDP(). In clientGET.py example please replace line: reactor.listenUDP(61616, protocol) with: reactor.listenUDP(0, protocol, interface='::0')

bencrundwell commented 7 years ago

Excellent, this fixed my issue too! Thanks @mwasilak