Reputation: 135
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);
}
Upvotes: 0
Views: 1888
Reputation: 15363
Start with an unconnected Socket
and supply a SocketAddress
with a long
timeout value on its the connect()
method.
Its actually pretty important that you set this or your connect operation will block(by default) for an indefinite amount of time
Upvotes: 1
Reputation: 7042
connection time out often occurs for slow response of server. check the net connection and server .
Upvotes: 0