您好,我用 Android 编写了一个服务器。以下是我的代码:-
SSLServerSocket ss=(SSLServerSocket)sslssf.createServerSocket(Constants.CHAT_SERVER_PORT);
final String[] enabledCipherSuites = { "SSL_DH_anon_WITH_RC4_128_MD5" };
ss.setEnabledCipherSuites(enabledCipherSuites);
while(true) {
Socket s=ss.accept();
OutputStream out=s.getOutputStream();
ObjectOutputStream oos=new ObjectOutputStream(out);
oos.flush();
Android android=new Android();
oos.writeObject(android);
InputStream sis= s.getInputStream();
ObjectInputStream ois=new ObjectInputStream(sis);
}
一切顺利。但是“OutputStream out=s.getOutputStream();”在上面的代码中花费了大量的时间。将近一分钟。我不确定为什么?请帮我解决这个问题?
以下是对应的客户端代码(桌面):-
SSLSocket socket= (SSLSocket)sslsf.createSocket(ip,Constants.CHAT_SERVER_PORT);
final String[] enabledCipherSuites = { "SSL_DH_anon_WITH_RC4_128_MD5" };
socket.setEnabledCipherSuites(enabledCipherSuites);
InputStream in=socket.getInputStream();
OutputStream out=socket.getOutputStream();
ObjectInputStream ois=new ObjectInputStream(in);
ObjectOutputStream oos=new ObjectOutputStream(out);
Object obj=ois.readObject();
SocketInfo sockInfo=new SocketInfo(socket,oos,ois,ip);
请帮助我解决这个问题。
最佳答案
这将是花时间的 SSL 握手。如果安卓支持javax.net.debug=ssl,handshake您可以查看它以了解更多信息。
但是你为什么要使用匿名密码套件。您知道它不安全吗?
关于java - socket.outputStream 为什么要花这么多时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16449325/