What are some reasons why a socket connection would fail with a given ip and port? Is there a way to fix this? On some occasion i would get a socket connection failure. But I would only find out after waiting for a few minutes. Is there a way to find out if a connection would fail in a shorter amount of time?
try{
socketConn = new Socket(this.ip, this.port);
}catch (IOException e){
System.err.println("Failed creating a Socket Connection in Peer constructor for " +id +
" with IP: " +ip+" and on port: "+port);
}
Start with an unconnected
Socketand supply aSocketAddresswith alongtimeout value on its theconnect()method.Its actually pretty important that you set this or your connect operation will block(by default) for an indefinite amount of time
Socket Javadoc