devBuzzy / pircbotx

Automatically exported from code.google.com/p/pircbotx
0 stars 0 forks source link

Network is unreachable #79

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Often when I try to connect to a server I get "Network is unreachable".

This problem, and a possible solution, is described here:
http://www.deaded.com/forum/viewtopic.php?showtopic=813

It appears the bot grabs the first IP from DNS and fails if it doesn't connect. 
 They suggest getting all the IP addresses for the host looping through to get 
a success.  Here is the code suggested by TTL.

// Clear everything we may have know about channels.
        this.removeAllChannels();
        InetAddress[] addy = InetAddress.getAllByName(hostname);

        // Connect to the server.
        Socket socket = null;
        for(int i = 0; i < addy.length;i++){
                InetAddress ia = addy[i];
                try{
                        socket = new Socket(ia,port);
                }
                catch(Throwable t){
                        this.log("*** Unable to connect to "+hostname+" using the IP address "+ia.getHostAddress()+", trying to check another address.");
                }
        }
        if(socket == null || (socket != null && !socket.isConnected())){
                this.log("*** Unable to connect to any working IP address for hostname "+hostname);
                throw new IOException("Unable to connect to the IRC network "+hostname);
        }
        //Socket socket =  new Socket(hostname, port);
        this.log("*** Connected to server.");

Original issue reported on code.google.com by jeffgem...@gmail.com on 26 Jul 2012 at 3:22

GoogleCodeExporter commented 9 years ago
TMK, network is unrechable is usually a network card level error meaning that 
the network your trying to connect to is unrechable over this interface. IE if 
you try to connect to 5.5.5.5 on an interface that only accepts 127.XXX.XXX.XXX 
addresses. I don't remember ever seeing that error for a simple "Cannot 
connect" error

With the code though, I am open to adding this to PircBotX as it could be 
useful. Should be in by tonight

Original comment by Lord.Qua...@gmail.com on 26 Jul 2012 at 6:18

GoogleCodeExporter commented 9 years ago
Added a modified version in Revision fcdcd901733d. Thanks for the code as it 
would of admittedly took me a while to come up with something like that

Pushed out a new snapshot if you want to try it 

Original comment by Lord.Qua...@gmail.com on 11 Aug 2012 at 11:56

GoogleCodeExporter commented 9 years ago

Original comment by Lord.Qua...@gmail.com on 11 Aug 2012 at 11:56