SocketTimeoutException当ConnectTimeout和ReadTimeout是无限的? [英] SocketTimeoutException when ConnectTimeout and ReadTimeout is infinite?

查看:2311
本文介绍了SocketTimeoutException当ConnectTimeout和ReadTimeout是无限的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/9986712/receiving-request-timeout-even-though-connect-timeout-and-read-timeout-is-set-to\">Receiving请求超时即使连接超时和读取超时设置为默认(无限)?


我试图连接到Web服务,大约20秒后收到一个 SocketTimeoutException 。托管Web服务的Tomcat服务器关闭,因此在例外的预期。但是,我没有把我的ConnectTimeout和ReadTimeout的价值。根据该文件,这两个的默认值是无限的。

这一种可能性是,我试图连接到服务器都有自己的超时时间。但是,当我的朋友试图使用的是iOS连接到它,他的连接超时后约1分钟15秒。如果该服务器是一个发出的超时,我们的连接应当在几乎相同的时间超时。请注意,他也是使用默认的超时的iOS。


  • 为什么我的插座超时这么早,当我连接和读取超时设置为无限期?

  • 是套接字超时不同的连接并读取超时?如果是这样,它是如何不同?

  • 我怎么能知道我的套接字超时值?我使用HttpURLConnection类。

  • 有没有一种方法来设置套接字超时?怎么样?

下面是我的code的一个片段:

  HttpURLConnection的=(HttpURLConnection类)((新URL(http://www.website.com/webservice))的openConnection());
httpURLConnection.setDoInput(isDoInput);
httpURLConnection.setDoOutput(isDoOutput);
httpURLConnection.setRequestMethod(方法);尝试
{
    OutputStreamWriter作家=新OutputStreamWriter(httpURLConnection.getOutputStream());
    writer.write(参数1 =值);
    writer.flush;
}赶上(例外五)
{}


解决方案

  为什么我的插座

为什么超时这么早,当我连接和读取超时设置为无限期?


code吧。


  

时套接字超时不同的连接并读取超时?如果是这样,它是如何不同?


SocketTimeoutException 是读超时。


  

我怎么能知道我的套接字超时值?我使用HttpURLConnection类。


HttpURLConnection.getReadTimeout();还 HttpURLConnection.getConnectTimeout()


  

有没有一种方法来设置套接字超时?怎么样?


HttpURLConnection.setReadTimeout()

您已经引用在<一个所有这些方法href=\"http://stackoverflow.com/questions/9986712/receiving-request-timeout-even-though-connect-timeout-and-read-timeout-is-set-to\">original帖子。你为什么要问他们在这里?

Possible Duplicate:
Receiving request timeout even though connect timeout and read timeout is set to default (infinite)?

I tried to connect to a web service and received a SocketTimeoutException after approximately 20 seconds. The Tomcat server hosting the web service is down so the Exception is expected. However, I did not set the value of my ConnectTimeout and ReadTimeout. According to the documentation, the default values of these two are infinite.

One possibility for this is that the server I tried connecting to has its own timeout. But when my friend tried to connect to it using iOS, his connection timed out after approximately 1 minute and 15 seconds. If the server is the one issuing the timeout, our connection should have timed out at almost the same time. Please note that he is also using the default time out of iOS.

  • Why did my socket timed out so early when my connect and read timeout are set to infinite?
  • Is socket timeout different to connect and read timeout? If so, how is it different?
  • How can I know the value of my socket timeout? I am using HttpURLConnection.
  • Is there a way to set the socket timeout? How?

Below is a snippet of my code:

httpURLConnection = (HttpURLConnection) ((new URL("http://www.website.com/webservice")).openConnection());
httpURLConnection.setDoInput(isDoInput);
httpURLConnection.setDoOutput(isDoOutput);
httpURLConnection.setRequestMethod(method);

try
{
    OutputStreamWriter writer = new OutputStreamWriter(httpURLConnection.getOutputStream());
    writer.write("param1=value1");
    writer.flush;
}catch(Exception e)
{

}

解决方案

Why did my socket timed out so early when my connect and read timeout are set to infinite?

Code please.

Is socket timeout different to connect and read timeout? If so, how is it different?

SocketTimeoutException is a read timeout.

How can I know the value of my socket timeout? I am using HttpURLConnection.

HttpURLConnection.getReadTimeout(); also HttpURLConnection.getConnectTimeout().

Is there a way to set the socket timeout? How?

HttpURLConnection.setReadTimeout().

You have already cited all these methods in your original post. Why are you asking about them here?

这篇关于SocketTimeoutException当ConnectTimeout和ReadTimeout是无限的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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