jensemil
jensemil

Reputation: 21

java.net.SocketException: Invalid argument

Error receiving connection: java.net.SocketException: Invalid argument Exception in thread "Thread-698" java.lang.RuntimeException: Did not establish input/output at Handin2.ConnectionHandlerImpl.run(ConnectionHandlerImpl.java:124) at java.lang.Thread.run(Thread.java:722)

I have been searching a lot on this exception. Everywhere it seems to be the conclusion that if you compile with the JVM option -Djava.net.preferIPv4Stack=true it will solve the problem. It doesn't for me though. I am running IntelliJ and trying to implement a Chord system with Sockets and Threads. This is where the above mentioned exception is caught and thrown:

if(this.remote == null || this.node == null) {
    throw new RuntimeException("Connection handler has not been properly "
                + "initalialized");
}
try{
    if(this.out == null) {
      this.out = new ObjectOutputStream(remote.getOutputStream());
    }
    if(this.in == null) {
      this.in = new ObjectInputStream(remote.getInputStream());
    }
} catch(IOException e) {
      System.out.println("Trying to make input/output for remote " + remote);
      System.err.println(node.getKey()/Constants.NORMALIZE_KEY+": Error receiving connection: " + e.toString());
      return false;
}

I don't know if more code snippets are needed in order to help, but I am simply lost on this exception since the solutions when searching are not helping at all.

Any hints on what triggers this error? The socket exception is caught by the given try-catch block as a special case of an IO exception

Upvotes: 2

Views: 3871

Answers (1)

user207421
user207421

Reputation: 311054

if you compile with the JVM option -Djava.net.preferIPv4Stack=true it will solve the problem.

No. If you execute with that JVM option. Nothing to do with the compiler.

Upvotes: 2

Related Questions