On Sun, Oct 12, 2014 at 8:07 AM, Victor Stinner <victor.stin...@gmail.com> wrote:
> I added an exampl of UDP server in asyncio documentation: > > https://docs.python.org/dev/library/asyncio-protocol.html#udp-echo-server-protocol > > My example is based on Tulip example examples/udp_echo.py. In Tulip > example, I see that the MyServerUdpEchoProtocol has error_received() > and connection_lost() methods. When are these methods called? UDP is > not a connected protocol, how can you loose a connection? > I think only Bram Cohen (Bittorrent creator/founder) knows. :-) I believe the scenario is as follows: you send a packet to a specific UDP host/port, but nothing is listening on that port. The host can then send an advisory lower-level error packet back (I think it may be ICMP) advising the sending host that there is nobody listening. The *next* time you are trying to send a UDP packet your app will then get the error. It may be the case that this only applies to UDP sockets that are "connected" -- which just means that the kernel has a default destination for packets that are being sent without an explicit destination (there is no actual connection setup exchange like for TCP). The connection_lost() callback is only called when the transport is closed using transport.close(). > For error_received, the documentation is here: > > https://docs.python.org/dev/library/asyncio-protocol.html#asyncio.DatagramProtocol.error_received > > Victor > -- --Guido van Rossum (python.org/~guido)