Java DatagramSocket 设置 keep-alive 选项 [英] Java DatagramSocket setting keep-alive option

查看:40
本文介绍了Java DatagramSocket 设置 keep-alive 选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆