如何使用Java(套接字)将SPOP3服务器连接/远程登录? [英] How to connect/telnet to SPOP3 server using java (Sockets)?
问题描述
对于POP3,可以使用端口110上的套接字通过telnet连接,但是如果实现了SPOP3,该怎么做. 使用普通的telnet,可以很容易地完成
In case of POP3 it is possible to connect via telnet using sockets over port 110, But how to do it , if SPOP3 is implemented. With normal telnet it can be done quite easily with
Socket pop3Socket = new Socket(host.com, 110);
仅供参考: 为了连接到SPOP3,我们在linux/unix中使用
FYI: For connecting to SPOP3 we use in linux/unix
openssl s_client -connect servername.com:995
推荐答案
您将需要使用SSLSocket类.可以在以下位置找到示例: http://www.herongyang. com/JDK/SSL-Socket-Client-Example-SslSocketClient.html .
You'll need to use the SSLSocket class. An example can be found at: http://www.herongyang.com/JDK/SSL-Socket-Client-Example-SslSocketClient.html.
基本上,您将执行以下操作:
Basically, you'll do something like:
SSLSocketFactory f = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket c = (SSLSocket) f.createSocket("localhost", 8888);
如果端点具有自签名证书,那么您有两个选择:
If the endpoint has a self signed certificate then you have two options:
- 将此自签名证书添加到您的本地密钥库中.该URL提供了很好的概述: http://www.chrissearle.org/blog/technical/adding_self_signed_https_certificate_java_keystore
- 创建一个不验证服务器证书的TrustManager: http://www.howardism .org/Technical/Java/SelfSignedCerts.html
- Add this self-signed cert to your local keystore. This URL gives a good overview: http://www.chrissearle.org/blog/technical/adding_self_signed_https_certificates_java_keystore
- Create a TrustManager that does not validate the server's certificate: http://www.howardism.org/Technical/Java/SelfSignedCerts.html
选项1更安全.
这篇关于如何使用Java(套接字)将SPOP3服务器连接/远程登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!