Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can cause “ IO error java.net.SocketException: select failed ”?

I have a server program running on my laptop, same router and same code. It work's fine and clients can connect. However when I copied the workspace to my PC and when I run it, I get this nonsense:

IO error java.net.SocketException: select failed

Here is the code...

public static void main(String[] args) {
    System.out.println("running server!");
        int nreq = 1;
        try{
            ServerSocket sock = new ServerSocket(7331);
        for(;;){
            Socket newsock = sock.accept();
            System.out.println("Creating thread...");
            //Thread t = new ThreadHandler(newsock, nreq);
            //t.start();
            nreq++;
        }
        }

        catch(Exception e)
        {

            System.out.println("IO error  " + e);

        }

Basically what could cause this error (of which I can find no useful information online) to happen on one PC and not another? It has to be something about the PC itself. I am most confused. Basically it can't open a socket?

Here is the full stacktrace:

java.net.SocketException: select failed
    at java.net.PlainSocketImpl.socketAccept(Native Method)
    at java.net.PlainSocketImpl.accept(Unknown Source)
    at java.net.ServerSocket.implAccept(Unknown Source)
    at java.net.ServerSocket.accept(Unknown Source)
    at Server.main(Server.java:18)

If it's relevant, I'm using Windows 7 64 bit Ultimate on the PC which is giving me problems. The laptop that it works fine on is Windows 7 32 bit. So the only discernible difference I can tell is 32 vs 64 bit.

Could this be relevant? I don't understand it. http://forums.codeguru.com/showthread.php?522257-Windows-Sockets-64-bit

like image 912
ILikeWater Avatar asked Feb 27 '26 21:02

ILikeWater


1 Answers

I've run into this because of permissions. I'm more accustomed to Linux where I would need to check the settings for IPTables (or disable it), permissions such as non-root users binding to ports < 1024. I believe on Windows you'll want to check your user's administrative rights and your Windows Firewall.

like image 177
MartyE Avatar answered Mar 02 '26 12:03

MartyE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!