好的,我以前用 Java 完成过线程,但我认为应该正确的事情是给我这个错误
package com.mdog.tcpserver; import java.net.*; import java.io.*; public class ServerDriver { public static void main(String[] args) throws IOException { ServerSocket serverSocket = null; boolean listening = true; /* bind welcome socket to port */ try { serverSocket = new ServerSocket(1313); } catch (IOException e) { System.err.println("Could not listen on port: 1313."); System.exit(1); } /* assign thread to each client */ while(listening){ new ServerWorker(serverSocket.accept()).start(); } /* close the socket and quit */ serverSocket.close(); return; } }
---------package com.mdog.tcpserver; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; public class ServerWorker implements Runnable { private Socket socket = null; public ServerWorker(Socket s){ super(); this.socket = s; } public void run() { (stuff happens) } }
错误在这一行“new ServerWorker(serverSocket.accept()).start();” 它说......“方法 start() 对于类型 ServerWorker 是未定义的”