DatagramChannel.close() keeps port open on Windows

前端 未结 2 884
我在风中等你
我在风中等你 2021-01-21 18:33

I\'m implementing a Discover process that:

  • Open a UDP socket to listen for broadcast response on a given port
  • Send some requests (and expect later respons
2条回答
  •  渐次进展
    2021-01-21 18:48

    Some parts of a channel close are deferred to the next select() if the channel is registered with a Selector. It is documented somewhere in the forest of Selector, AbstractSelector, SelectorSpi, SelectableChannel, AbstractSelectableChannel, where I can never find it when I need it. If you're within the select loop and thread when you close the channel, you can make it immediate by calling selectNow().

提交回复
热议问题