我在64位操作系统(Windows 7 Ultimate)上运行时遇到了一个奇怪的异常,但在32位Win7 Ultimate上运行时没有出现。目前正在使用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();