Java SSLServerSocket soTimeout 不起作用?
我正在使用用 Java 编写的 Apache Thrift 服务器。当我创建 ServerSocket 时,我传递了一个名为 clientTimeout 的参数,其值为 60000(十分钟)。但这没有按预期工作 - 我连接到服务器,执行一个方法,等待 11 分钟再次执行方法,无需重新连接,并且没有收到错误(正如我预期的那样)。 我尝试在非 SSL thrift 服务器上执行此操作,效果很好。 在 Thrift 来源中,我发现了如何创建 SSL 套接字,看起来不错。
private static TServerSocket createServer(SSLServerSocketFactory factory, int port, int timeout, boolean clientAuth,
InetAddress ifAddress, TSSLTransportParameters params) throws TTransportException {
try {
SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(port, 100, ifAddress);
serverSocket.setSoTimeout(timeout);
serverSocket.setNeedClientAuth(clientAuth);
if (params != null && params.cipherSuites != null) {
serverSocket.setEnabledCipherSuites(params.cipherSuites);
}
return new TServerSocket(serverSocket);
} catch (Exception e) {
throw new TTransportException("Could not bind to port " + port, e);
}
}
有人有这样的问题吗?如何修复它?
I'm using Apache Thrift server written on Java. When i'm create ServerSocket i'm pass a parameter called clientTimeout with value 60000 (ten minutes). But this not work as expected - i'm connect to server, execute a method wait 11 minutes execute method again without reconnect and didn't get error (as i'm expected).
I'm try do it on not SSL thrift server, this work fine.
In thrift sources i'm found how to SSL socket created, seems ok.
private static TServerSocket createServer(SSLServerSocketFactory factory, int port, int timeout, boolean clientAuth,
InetAddress ifAddress, TSSLTransportParameters params) throws TTransportException {
try {
SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(port, 100, ifAddress);
serverSocket.setSoTimeout(timeout);
serverSocket.setNeedClientAuth(clientAuth);
if (params != null && params.cipherSuites != null) {
serverSocket.setEnabledCipherSuites(params.cipherSuites);
}
return new TServerSocket(serverSocket);
} catch (Exception e) {
throw new TTransportException("Could not bind to port " + port, e);
}
}
has anyone such problem? How to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ServerSocket
上的超时仅影响ServerSocket.accept()
。它不会被接受的Socket
继承为读取超时。如果你想要这样,你必须明确地设置它。这是 Java API 和 BSD Sockets API 之间的区别。The timeout on a
ServerSocket
affectsServerSocket.accept()
only.It is not inherited by acceptedSockets
as a read timeout. If you want that, you have to set it explicitly. This is a difference between the Java API and the BSD Sockets API.