在我的应用程序中,我连接到服务器来验证用户.这是代码:
- try {
- Properties prop = new Properties();
- prop.put("mail.smtp.starttls.enable","true");
- prop.put("mail.smtp.auth","true");
- prop.put("mail.smtp.connectiontimeout",1000);
- Session session = Session.getInstance(prop,null);
- Transport transport = session.getTransport("smtp");
- transport.connect("mion.elka.pw.edu.pl",587,registerLog,registerPass);
- transport.close();
- return true;
- } catch (NoSuchProviderException ex) {
- Logger.getLogger(RegisterController.class.getName()).log(Level.SEVERE,null,ex);
- return false;
- } catch(AuthenticationFailedException ex) {
- Logger.getLogger(RegisterController.class.getName()).log(Level.SEVERE,ex);
- return false;
- } catch (MessagingException ex) {
- Logger.getLogger(RegisterController.class.getName()).log(Level.SEVERE,ex);
- return false;
- }
我将连接超时设置为1000 ms = 1s,但忽略.当我调试并设置错误的用户名和密码我抓住
- javax.mail.MessagingException: java.net.SocketTimeoutException: Read timed out
不是在1000 ms后,但在5000 * 60 ms = 5分钟后
哪里不对 ?我如何减少时间?
@R_404_323@
您还可以设置Socket I / O超时.当连接但未能从服务器读取数据时,它将继续等待.
- prop.put("mail.smtp.timeout",1000);
读取超时表示您已连接,但无法从服务器读取数据.