3

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

ILikeWater
  • 31
  • 4
  • It sounds like it says that there is no connection and it throws an exception because of it. – Cole Tobin Aug 12 '12 at 23:46
  • What do you mean? I am online with the same computer right now. It's just supposed to be opening the port to listen for incoming client connections on, this program does not need to establish any client-server connections to start running, and it's failing to even run. – ILikeWater Aug 12 '12 at 23:53
  • Line 18 is: Socket newsock = sock.accept(); – ILikeWater Aug 12 '12 at 23:53
  • @ColeJohnson ServerSocket.accept() is supposed to block until there *is* a connection. – user207421 Aug 13 '12 at 00:15
  • @EJP, That's interesting. What do you make of this then? There should be no incoming connections till I initiate one on my client. It fails this way from the moment I click run. This sounds like a good hint but I'm not sure how to interpret it. – ILikeWater Aug 13 '12 at 00:38
  • I have no idea frankly. I don't even know why the implementation is calling select() at all. – user207421 Aug 13 '12 at 01:24
  • Has OP looked at possible "Error between Chair and keyboard" type problems How are you executing this code? – nsfyn55 Aug 13 '12 at 01:52
  • @ NSFYN55, define executing. I'm running it in eclipse same as laptop. – ILikeWater Aug 13 '12 at 03:14
  • Your link is relevant if you have linked some JNI code that uses -Zp1; not otherwise, unless you are prepared to believe that Oracle built the JVM that way, which doesn't seem even slightly probable or it wouldn't work at all according to what your link says. – user207421 Aug 14 '12 at 00:20

1 Answers1

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.

MartyE
  • 636
  • 3
  • 7