只有在 64 位(Windows 7 终极版)上运行时才会出现这个奇怪的异常,而不是在运行 32 位 Win7 终极版时。目前它在 java 版本 1.6.0_26 上运行
running server!
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)
这是代码:
//import java.net.ServerSocket;
//import java.net.Socket;
import java.io.*;
import java.net.*;
public class Server {
public static void main(String[] args) {
System.out.println("running server!");
int nreq = 1;
try{
ServerSocket sock = new ServerSocket(7337);
for(;;){
Socket newsock = sock.accept();
System.out.println("Creating thread...");
Thread t = new ThreadHandler(newsock, nreq);
t.start();
nreq++;
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
在线引用的错误指向该位:
Socket newsock = sock.accept();