package message;import java.io.*;
import java.net.*;
完全照着书上敲进去的啊!网络编程这块的例子,高手帮我看看吧
public class MutilServer {
final static int PORT = 8080; public static void main(String[] args) throws IOException {
ServerSocket s = new ServerSocket(PORT);
System.out.println("开始监听,端口号:" + PORT);
try {
while (true) {
Socket socket = s.accept(); try {
new ServerThread(socket);//这句哪里错了?
} catch (IOException e) {

socket.close();
} }
} finally {
s.close();
} } class ServerThread extends Thread {
private Socket socket; private BufferedReader in; private PrintWriter out; public ServerThread(Socket s) throws IOException {
socket = s;
in = new BufferedReader(new InputStreamReader(socket
.getInputStream()));
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
socket.getOutputStream())), true);
start();
}
public void run() {
try {
while (true) {
String str = in.readLine();
if (str.equals("END")) {
break;
}
System.out.println("客户端:" + str);
out.println("知道了:" + str);
}
System.out.println("正在关闭连接");
socket.close();
} catch (IOException e) {

e.printStackTrace();
} finally {
try {
socket.close();
} catch (IOException e) { e.printStackTrace();
} }
} }
}

解决方案 »

  1.   

    哥呀 你有这个ServerThread类么?
    你干脆全抛exception得了
      

  2.   

    你把ServerThread这个类放到外边去,就可以了。
      

  3.   

    有啊,在下面呢,没有public,写一块了
      

  4.   

    大括号闭合顺序错了,把最后一个 } 放到class ServerThread extends Thread 这句的上面
      

  5.   

    static  class ServerThread extends Thread {
    或者把MyMonitor定义在ChuangKou外面。非静态嵌套类必须在外套类的非静态成员里构造这样就不会有错了
      

  6.   

    new Test2.ServerThread(socket);试一下