This seems to be the only place to remove natsession. But the trigger condition is only sending failure (UDP sending failure is either due to disconnection or wrong server address). If the connection is completed and the client have received reply from
the server, the UDP connection will be auto closed, but the natsession does not seem to be released.
There is also a situation where the server address is correct, but the server is not online, or the server does not reply. In this case, there will be no exception. If the timeout is not set, the UDP client will always be blocked in the "waiting for server reply" stage.
请问项目是如何判断 UDP 连接已经结束并释放资源的?
https://github.com/mightofcode/android-vpnservice/blob/228dd77e8db010c81ea3c5b7b258590be5a78f88/app/src/main/java/com/mocyx/basic_client/bio/BioUdpHandler.java#L199-L202
这里似乎是唯一移除
natsession
的地方。但是触发条件仅是发送失败(UDP 发送失败要么是断网要么是服务器地址错误)。如果正常发送完成并接收完回复,udp 连接会自动释放,但natsession
似乎没有释放。而且还有一种情况是服务器地址合法,但是服务器不在线,或者服务器不回复,这种情况下是不会出异常的。如果不设置超时,UDP 客户端会一直阻塞在“等待服务器回复”这个阶段。
This seems to be the only place to remove
natsession
. But the trigger condition is only sending failure (UDP sending failure is either due to disconnection or wrong server address). If the connection is completed and the client have received reply from the server, the UDP connection will be auto closed, but thenatsession
does not seem to be released. There is also a situation where the server address is correct, but the server is not online, or the server does not reply. In this case, there will be no exception. If the timeout is not set, the UDP client will always be blocked in the "waiting for server reply" stage.