我有一个使用 SSLSocket 连接到服务器的客户端。接下来,我尝试创建一个OOSObjectOutputStream oos = new ObjectOutputStream(sslsocket.getOutputStream());
如果服务器端一切正常,这很好。但是,我想在我的客户端放置一些东西来尝试创建 ObjectOutputStream,但如果它在 60 秒内没有发生,请记录错误并继续处理。我没有看到任何超时选项。有什么可以做到这一点的例子吗?
SSLSocket sslsocket;
try {
System.setProperty("javax.net.ssl.trustStore", <myKeystore>);
System.setProperty("javax.net.ssl.trustStorePassword", <myPW>);
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
sslsocket = (SSLSocket) sslsocketfactory.createSocket(InetAddress.getLocalHost(), <myPort>);
} catch (Throwable e) {
logger.logError(e.getMessage());
return null;
}
// This is where it hangs forever
ObjectOutputStream oos = new ObjectOutputStream(sslsocket.getOutputStream());
oos.flush(); // never gets here
oos.writeObject(orders);
ObjectInputStream ois = new ObjectInputStream(sslsocket.getInputStream());