标签: connectexception

当URL启动时,为什么会出现"java.net.ConnectException:Connection timed out"异常?

ConnectException: Connection timed out从代码中获得了一些频率.我试图点击的网址已经启动.相同的代码适用于某些用户,但不适用于其他用户.似乎一旦一个用户开始获得此异常,他们就会继续获得异常.

这是堆栈跟踪:

java.net.ConnectException: Connection timed out
Caused by: java.net.ConnectException: Connection timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.Socket.connect(Socket.java:516)
    at java.net.Socket.connect(Socket.java:466)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
    at sun.net.www.http.HttpClient.New(HttpClient.java:287)
    at sun.net.www.http.HttpClient.New(HttpClient.java:299)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:796)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:748)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:673)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:840)
Run Code Online (Sandbox Code Playgroud)

以下是我的代码中的代码段:

URLConnection urlConnection = null;
OutputStream outputStream = null;
OutputStreamWriter outputStreamWriter = null;
InputStream inputStream = null;

try {
    URL url = new URL(urlBase);
    urlConnection = url.openConnection();
    urlConnection.setDoOutput(true);

    outputStream = …
Run Code Online (Sandbox Code Playgroud)

java connection urlconnection connectexception

81
推荐指数
5
解决办法
41万
查看次数

Hadoop集群设置 - java.net.ConnectException:连接被拒绝

我想在伪分布式模式下设置一个hadoop-cluster.我设法执行所有设置步骤,包括在我的机器上启动Namenode,Datanode,Jobtracker和Tasktracker.

然后我尝试运行一些示例程序并面对java.net.ConnectException: Connection refused错误.我回到了以独立模式运行某些操作的最初步骤,并遇到了同样的问题.

我甚对所有安装步骤进行了三重检查,并且不知道如何修复它.(我是Hadoop和初学Ubuntu用户的新手,因此,如果提供任何指南或提示,我恳请您"考虑到它").

这是我一直收到的错误输出:

hduser@marta-komputer:/usr/local/hadoop$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.6.0.jar grep input output 'dfs[a-z.]+'
15/02/22 18:23:04 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
15/02/22 18:23:04 INFO client.RMProxy: Connecting to ResourceManager at /0.0.0.0:8032
java.net.ConnectException: Call From marta-komputer/127.0.1.1 to localhost:9000 failed on connection exception: java.net.ConnectException: Connection refused; For more details see:  http://wiki.apache.org/hadoop/ConnectionRefused
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.apache.hadoop.net.NetUtils.wrapWithMessage(NetUtils.java:791)
    at org.apache.hadoop.net.NetUtils.wrapException(NetUtils.java:731)
    at …
Run Code Online (Sandbox Code Playgroud)

java configuration hadoop connectexception

46
推荐指数
3
解决办法
12万
查看次数

CommunicationException [Root 异常是 ConnectException: Connection timed out]

我在尝试连接 Active Directory 时偶尔会遇到此异常。

javax.naming.CommunicationException: <ServerIP>:<PORT> 
  [Root exception is java.net.ConnectException: Connection timed out: connect]
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

    DirContext ctx = null;
    Properties env = new Properties();

    env.put(Context.SECURITY_PRINCIPAL, <Bind_USER>);
    env.put(Context.SECURITY_CREDENTIALS, <Bind_USER_PWD>);
    env.put(Context.PROVIDER_URL, "ldap://<ServerIP>:<PORT>");            
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

    ctx = new InitialDirContext(env);
Run Code Online (Sandbox Code Playgroud)

在此行中获取连接超时异常ctx = new InitialDirContext(env);。它不会每次都发生,但经常发生。

请告诉我,如何摆脱这个问题?

java runtime-error ldap communicationexception connectexception

5
推荐指数
1
解决办法
3万
查看次数

cassandra nodetool:无法连接到“127.0.0.1:7199”

我在centos7和vmware上安装了cassandra 3.11.3-1

\n\n

我安装 cassandra 时没有出现错误。\ni 启动 cassandra 并面对此日志。

\n\n
[root@localhost ~]# service cassandra start\nStarting cassandra (via systemctl):                        [  OK  ]\n\n[root@localhost ~]# systemctl status cassandra\ncassandra.service - LSB: distributed storage system for structured data\nLoaded: loaded (/etc/rc.d/init.d/cassandra; bad; vendor preset: disabled)\nActive: deactivating (stop) (Result: exit-code) since 2018-08-02 15:15:45 \nKST; 6s ago\nDocs: man:systemd-sysv-generator(8)\nProcess: 10366 ExecStart=/etc/rc.d/init.d/cassandra start (code=exited, \nstatus=0/SUCCESS)\nMain PID: 10450 (code=exited, status=3);         : 10478 (cassandra)\nTasks: 2\nCGroup: /system.slice/cassandra.service\n         \xe2\x94\x94\xe2\x94\x80control\n            \xe2\x94\x9c\xe2\x94\x8010478 /bin/bash /etc/rc.d/init.d/cassandra stop\n            \xe2\x94\x94\xe2\x94\x8010549 sleep 0.5\n\n 02 15:15:39 localhost.localdomain systemd[1]: Starting LSB: distributed \n …
Run Code Online (Sandbox Code Playgroud)

cassandra connectexception nodetool

4
推荐指数
1
解决办法
4万
查看次数

发送邮件时出错 - ConnectException

我使用以下Java代码发送电子邮件.

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendEmail
{
   public static void main(String [] args)
   {    

      String to = "abcd@gmail.com";
      String from = "web@gmail.com";
      String host = "localhost";
      Properties properties = System.getProperties();
      properties.setProperty("smtp.gmail.com", host);
      Session session = Session.getDefaultInstance(properties);
      try{
         MimeMessage message = new MimeMessage(session);
         message.setFrom(new InternetAddress(from));
         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to))
         message.setSubject("This is the Subject Line!");
         message.setText("This is actual message");
         Transport.send(message);
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

当我运行该文件时,我收到以下错误:

javax.mail.MessagingException: Could not connect to …
Run Code Online (Sandbox Code Playgroud)

java email javax.mail connectexception

3
推荐指数
1
解决办法
3万
查看次数

HttpsURLConnection:连接超时错误

我有一个简单的代码,用于设置与谷歌的https连接并打印获得的响应.

import java.io.OutputStreamWriter;
import java.net.URL;

import javax.net.ssl.HttpsURLConnection;


public class SendCertReq 
{
public static void main(String[] args) throws Exception 
{
     URL url = new URL("https://www.google.co.in/");
     HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
     conn.setRequestMethod("GET");
     conn.setDoOutput(true);
     OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
     wr.close();
     System.out.println(conn.getResponseMessage());
}
}
Run Code Online (Sandbox Code Playgroud)

我尝试运行它时出现以下错误.

Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
at sun.security.ssl.BaseSSLSocketImpl.connect(Unknown Source)
at …
Run Code Online (Sandbox Code Playgroud)

java https connectexception

3
推荐指数
1
解决办法
2万
查看次数

抛出ConnectException之前的Java延迟

我正在用Java编写一些代码来从网址下载内容,在我的配置中,一些下载应该由代理处理,而其他人则不需要处理.

所以我编写了这个代码(它可以工作)来下载所有的URL类型,但是我想减少抛出ConnectException之前的延迟时间,这样代码可以更快地执行.

URL global_url = new URL("http://google.com");
Scanner sc = null;
try { 
    sc = new Scanner(global_url.openStream());
}
catch (ConnectException e) {
    try {
        System.setProperty("http.proxyHost", "my.host");
        System.setProperty("http.proxyPort", "my.port");
        sc = new Scanner(global_url.openStream());
        System.setProperty("http.proxyHost", "");
        System.setProperty("http.proxyPort", "");
    }
    catch (ConnectException exc) {
        //Do stuff
    }
}
Run Code Online (Sandbox Code Playgroud)

现在需要约.抛出异常前10秒,我想把这个时间减少到最多2s或3s.

我可以得到一些帮助吗?谢谢 !

java exception delay throw connectexception

3
推荐指数
1
解决办法
352
查看次数

JavaMail - 设置端口、代理和防火墙

我正在尝试制作一个非常简单的电子邮件应用程序,并且我已经编写了几行基本代码。我不断收到的一个例外是com.sun.mail.util.MailConnectException. 有没有一种简单的方法可以通过代理或防火墙进行编码,而不会扰乱发送计算机的连接设置?

到目前为止我的代码:

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

public class SendHTMLMail {
public static void main(String[] args) {
    // Recipient ID needs to be set
    String to = "test@test.com";

    // Senders ID needs to be set
    String from = "mytest@test.com";

    // Assuming localhost
    String host = "localhost";

    // System properties
    Properties properties = System.getProperties();

    // Setup mail server
    properties.setProperty("mail.smtp.host", host);

       //Get default session object
    Session session = Session.getDefaultInstance(properties);

    try {
        // Default MimeMessage object
        MimeMessage mMessage = …
Run Code Online (Sandbox Code Playgroud)

java proxy firewall jakarta-mail connectexception

3
推荐指数
1
解决办法
3万
查看次数

Java RMI使用还是不使用SecurityManager

经过大量的搜索和反复试验后,我仍然无法确定是否需要安全管理器,如果需要,如何确定它是否可以工作。

启动服务器的代码:

    Registry registry;
    try {
        System.setProperty("java.security.policyfile", "\\\\...\\security.policy");
        if (System.getSecurityManager() == null) {
            RMISecurityManager securityManager = new RMISecurityManager();
            System.setSecurityManager(securityManager);
        }
        registry = LocateRegistry.createRegistry(port);
        registry.bind(serviceName, remote);
        System.out.println("RMI registry created.");
    } catch (RemoteException e) {
        //error means registry already exists
        System.out.println("RMI registry already exists.");
    }
    System.setProperty("java.rmi.server.hostname", hostURL);
    Naming.rebind(hostURL, remote);
Run Code Online (Sandbox Code Playgroud)

服务器上的错误消息:

D:\>java -jar Server.jar
RMI server starting up
RMI registry created.
Exception in thread "main" ...Exception: Unable to start the Remote Server Server[UnicastServerRef [liveRef: [...]]
        at ServiceProvider.start(ServiceProvider.java:64)
        at Server.main(Server.java:76)
Caused by: java.security.AccessControlException: access …
Run Code Online (Sandbox Code Playgroud)

java rmi securitymanager connectexception

2
推荐指数
1
解决办法
4825
查看次数

Netty 4.0.x正确捕获ConnectException

我正在使用Netty开发一个应用程序,我需要在客户端处理ConnectException,以防万一,例如,连接超时.

这是代码

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;

public class ConnectTest {

public static void main(String[] args) throws Exception {
    Bootstrap b = new Bootstrap();
    b.group(new NioEventLoopGroup()).channel(NioSocketChannel.class)
    .handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {

        }
    });
    final ChannelFuture f = b.connect("0.0.0.0", 8080);
    f.addListener(new FutureListener<Void>() {

        @Override
        public void operationComplete(Future<Void> future) throws Exception {
            if (!f.isSuccess())
                System.out.println("Test Connection failed");
        }
    });
    f.sync();
}
}
Run Code Online (Sandbox Code Playgroud)

这就是结果:

        Test Connection …

java netty connectexception

2
推荐指数
1
解决办法
3358
查看次数