问题描述
我正在尝试使用 keep-alive 选项创建一个 datagramsocket 和 datagrampacket 发送.我对如何设置这个感到困惑.有没有像 datagramsocket.setKeepAlive(true);
那样简单的方法?
I'm trying to create a datagramsocket with and datagrampacket to send with the keep-alive option. I'm confused about how to set this though. Is there a simple way to do it like datagramsocket.setKeepAlive(true);
?
抱歉,我的意思是设置数据包的生存时间.有没有办法设置它,如果没有收到,它会一直保留到收到为止?
Sorry, I meant setting the time to live of a packet. Is there a way I can set it so if it isn't received, it will stay until it is received?
推荐答案
UDP 是所谓的无连接协议,即没有建立连接,你只是将数据包发送到一个 ip 地址/端口元组.既然没有连接,就没有什么可以存活的.
UDP is what's called connectionless protocol, i.e. no connection is established, you just send packets to an ip address/port tuple. Since there is no connection, there is nothing to keep alive.
这篇关于Java DatagramSocket 设置 keep-alive 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!