如何设置socket超时的时间?

huihuang 2006-04-19 09:25:48
new socket到目的地时要很久才有反应,不知道怎么设置这个超时的时间?
...全文
473 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
gongzhy 2006-09-12
  • 打赏
  • 举报
回复
Socket.setSoTimeout(int timeout);
xstom19 2006-09-12
  • 打赏
  • 举报
回复
可以这样:
Socket s = new Socket();
s.connect(new InetSocketAddress(host, port), timeout);
zuguanqun 2006-09-12
  • 打赏
  • 举报
回复
setSoTimeout(int time);
lmclmc000 2006-06-14
  • 打赏
  • 举报
回复
我也想知道
htt80 2006-05-22
  • 打赏
  • 举报
回复
楼上各位没有考虑到这个socket没有实例化能设置它的属性么?
btb368 2006-04-19
  • 打赏
  • 举报
回复
setSoTimeout(int timeout)
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
单位是毫秒的。如果要设计超时为10秒就要设置成setSoTiomeout(10000);
cyxlsm 2006-04-19
  • 打赏
  • 举报
回复
socket.setSoTimeout(2000);
cyxlsm 2006-04-19
  • 打赏
  • 举报
回复
setSoTimeout()可以设定socket连接的连接响应超时

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧