Java sun SSLSocketImpl没有连接超时,是否存在潜在错误?
最近,当客户端应用程序连接到服务器时,我们遇到了SocketTimeoutException。客户端应用程序使用Axis1.4作为SOAP引擎。我们已经将套接字的连接超时和读取超时设置为20秒,但连接超时值似乎不起作用 在深入研究JDK中的套接字创建之后,使用的套接字工厂是sun.security.ssl.sslsocketfactorympl,套接字工厂是sun.security.ssl.SSLSocketImpl。问题在于SSLSocketImpl的初始化,它将连接超时值硬编码为0,这意味着没有超时:Java sun SSLSocketImpl没有连接超时,是否存在潜在错误?,java,sockets,socket-timeout-exception,sslsocketfactory,Java,Sockets,Socket Timeout Exception,Sslsocketfactory,最近,当客户端应用程序连接到服务器时,我们遇到了SocketTimeoutException。客户端应用程序使用Axis1.4作为SOAP引擎。我们已经将套接字的连接超时和读取超时设置为20秒,但连接超时值似乎不起作用 在深入研究JDK中的套接字创建之后,使用的套接字工厂是sun.security.ssl.sslsocketfactorympl,套接字工厂是sun.security.ssl.SSLSocketImpl。问题在于SSLSocketImpl的初始化,它将连接超时值硬编码为0,这意味着
SSLSocketImpl(SSLContextImpl context, InetAddress host, int port)
throws IOException {
super();
init(context, false);
SocketAddress socketAddress = new InetSocketAddress(host, port);
connect(socketAddress, 0);
}
连接方式为:
/**
* Connects this socket to the server with a specified timeout
* value.
*
* This method is either called on an unconnected SSLSocketImpl by the
* application, or it is called in the constructor of a regular
* SSLSocketImpl. If we are layering on top on another socket, then
* this method should not be called, because we assume that the
* underlying socket is already connected by the time it is passed to
* us.
*
* @param endpoint the <code>SocketAddress</code>
* @param timeout the timeout value to be used, 0 is no timeout
* @throws IOException if an error occurs during the connection
* @throws SocketTimeoutException if timeout expires before connecting
*/
public void connect(SocketAddress endpoint, int timeout)
throws IOException {
if (self != this) {
throw new SocketException("Already connected");
}
if (!(endpoint instanceof InetSocketAddress)) {
throw new SocketException(
"Cannot handle non-Inet socket addresses.");
}
super.connect(endpoint, timeout);
doneConnect();
}
为什么sun的实现硬编码为0?这是虫子吗?从这一点来看,应用程序本身需要处理超时,这很奇怪
我们已经将套接字的连接超时和读取超时设置为20秒
不,你没有。您调用了SSLSocketFactory.createSocket(主机、端口)
,它没有超时参数。因此使用了默认值
这是虫子吗
没有。您没有使用连接超时,因此它使用默认值
为什么sun的实现硬编码为0
因为这是默认值。Hi,请参阅构造函数,在初始化过程中,它有“connect(socketAddress,0)”,此处设置为零。如果应用程序显式调用“publicvidyconnect(address,timeout)”,那么您肯定可以设置将超时值传递给该方法。如果应用程序使用套接字工厂创建套接字,则调用构造函数,此时始终使用零。当然,使用零。这是默认值。如果需要定时连接,则必须创建一个未连接的套接字,然后调用
connect()
。