我刚才试的
服务器端:
import java.net.*;
import java.util.*;
import java.io.*;
public class test {
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(12731);
Socket[] s = new Socket[10];
int i = 0;
for (;;) {
Socket sss = ss.accept();
for (int j = 0; j < 10; ++j) {
if (s[j]!= null)
System.out.println(j + ":" + s[j].isOutputShutdown());
if ((s[j] == null) || s[j].isOutputShutdown()) {
s[j] = sss;
System.out.println(j);
break;
}
}
}
} catch(IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
客户端:
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
public class test2 {
public static void main(String[] args) throws Exception {
Socket s = new Socket("127.0.0.1", 12731);
s.close();
}
}
然后发现服务器端无法检测到客户端已断开,然后就不知道该怎么办了。。