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

空扰寡人 提交于 2019-12-10 10:21:05

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/11926655/what-can-cause-io-error-java-net-socketexception-select-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!