java socket超时时间_java中socket 默认超时时间 | 学步园
MS:永远吧
Java代码
connect
publicvoidconnect(SocketAddress endpoint,
inttimeout)
throwsIOException
Connectsthissocket to the server with a specified timeout value.
A timeout of zero is interpreted as an infinite timeout.
The connection will then block until established or an error occurs.
Parameters:
endpoint - the SocketAddress
timeout - the timeout value to be used in milliseconds.
Throws:
IOException -ifan error occurs during the connection
SocketTimeoutException -iftimeout expires before connecting
IllegalBlockingModeException -
ifthissocket has an associated channel, and the channel is in non-blocking mode
IllegalArgumentException -
ifendpoint isnullor is a SocketAddress subclass not supported bythissocket
Since:
1.4
connect
public void connect(SocketAddress endpoint,
int timeout)
throws IOException
Connects this socket to the server with a specified timeout value.
A timeout of zero is interpreted as an infinite timeout.
The connection will then block until established or an error occurs.
Parameters:
endpoint - the SocketAddress
timeout - the timeout value to be used in milliseconds.
Throws:
IOException - if an error occurs during the connection
SocketTimeoutException - if timeout expires before connecting
IllegalBlockingModeException -
if this socket has an associated channel, and the channel is in non-blocking mode
IllegalArgumentException -
if endpoint is null or is a SocketAddress subclass not supported by this socket
Since:
1.4
选自java API :java.net.Socket
Socket socket = new Socket();
SocketAddress address = new InetSocketAddress("127.0.0.1", 8080);
try {
socket.connect(address, 60000);
SocketTimeoutException
} catch (IOException e) {
e.printStackTrace();
}
使用Socket.connect(SocketAddress sa, int timeout)方法。timeout为毫秒数,为0则永不超时(Socket默认也是如此)。如果到时间,仍然没有连接成功,则抛出SocketTimeoutException,在java.net包中。
java socket超时时间_java中socket 默认超时时间 | 学步园相关推荐
- java socket 阻塞模式_Java中Socket Read阻塞问题
本人来说并不熟悉JAVA语言,只是近期在分析某个简单的java agent程序时,根据对应的代码写了一个对接的程序,两者之间是典型的C/S socket编程.客户端在向服务端发送相应的指令后,服务端( ...
- java socket调用接口_Java中socket接口调用
最近一个项目中接口通讯这一块主要是调用银联系统的socket接口,我方是客户端,即发送请求接收返回报文的一方.在贴代码之前,还是要了解一下关于socket的基础知识. Socket的基本概念 1.建立 ...
- java中socket编程实例_Java中socket编程的实现过程(代码实例)
本篇文章给大家带来的内容是关于socket编程的实现过程,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 1.socket 服务器搭建 实例化socket服务器,循环获取请求packa ...
- java中定义一个时间_Java中的日期和时间
根据个人目前正在编写的<Java核心编程-基础篇>的规划,这部分属于第15章内容,这里沿用了书中的章节编号.另外,因为原文篇幅太长,这里适当做了删减. 15.1.概述 在 Java 8 之 ...
- java怎么获取当前日期_JAVA中获取当前系统时间
一. 获取当前系统时间和日期并格式化输出: import java.util.Date; import java.text.SimpleDateFormat; public class NowStri ...
- java中取系统时间_JAVA中获取当前系统时间(示例代码)
一. 获取当前系统时间和日期并格式化输出: import java.util.Date;import java.text.SimpleDateFormat; public class NowStrin ...
- 在java中获取当前时间_JAVA中获取当前系统时间
一. 获取当前系统时间和日期并格式化输出: import java.util.Date; import java.text.SimpleDateFormat; public class NowStri ...
- java 获得当前时间_JAVA中获取当前系统时间
一. 获取当前系统时间和日期并格式化输出: import java.util.Date; import java.text.SimpleDateFormat; public class NowStri ...
- java date当前时间_JAVA中获取当前系统时间
一. 获取当前系统时间和日期并格式化输出: import java.util.Date; import java.text.SimpleDateFormat; public class NowStri ...
- java输出当前时间_JAVA中获取当前系统时间 - Matrix54 - 博客园
JAVA中获取当前系统时间 - Matrix54 - 博客园 一. 获取当前系统时间和日期并格式化输出: import java.util.Date; import java.text.SimpleD ...
最新文章
- AI换脸技术再创新高度,DeepMind发布的VQ-VAE二代算法有多厉害?
- linux的磁盘磁头瓷片作用,Linux 磁盘管理
- boost::hana::less用法的测试程序
- smb服务器配置过程遇到错误及解决
- java ee的小程序_用微服务和容器替换旧版Java EE应用程序服务器
- Java这些多线程基础知识你会吗?
- 很不错的Windows 控件 Developer Express Inc.NET
- 神奇的 SQL 之团结的力量 → JOIN
- dyld Library not loaded @rpath libswiftCore dylib 解决
- Servlet→简介、手动编写一个Servlet、使用MyEclipse编写一个Servlet、Servlet生命周期、路径编写规范、初始化参数、MVC设计模式
- 如何用文件对比工具进行文件内容比较
- Qt PDF预览功能实现汇总
- JavaScript-68:数组的使用
- 整理了100个必备的 Python 函数,值得收藏
- portal服务器认证系统有哪些,portal服务器认证过程问题
- 如何将夜晚图片转化为白天图片 matlab,Python|记一次图片夜景效果尝试
- 目标识别数据集扩充方法
- 当当网页制作html代码,网页制作语言:HTML
- 性能检测工具:Matrix-TraceCanary 入门
- JS:指定FPS帧频,requestAnimationFrame播放动画
热门文章
- 维基链(WICC)当前币值应该还远远没有达到它本身应有的高度
- 比特币现金在稳定币领域的地位怎样
- 下一个全球电子通道系统,一定是BCH!
- 比特币现金社区推出OP_RETURN的4字节前缀指南
- python类方法以及类调用实例方法的理解
- shell中数组基础语法
- Linux Kernel Coding Style
- Silverlight/Windows8/WPF/WP7/HTML5周学习导读(6月25日-7月1日)
- ctags: 提示错误ctags: unrecognized option '--format=2'
- windows篇-第四章 安装和配置Windows域