日期:2014-05-20 浏览次数:20758 次
import java.io.*; import java.net.*; import java.util.*; public class ThreadedEchoServer { public static void main(String[] args) { // TODO Auto-generated method stub try { int i = 1; ServerSocket ss = new ServerSocket(8191); while (true) { Socket incoming = ss.accept(); System.out.println("Spawning " + i); Runnable r = new ThreadedEchoHandler(incoming, i); Thread t = new Thread(r); t.start(); i++; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } class ThreadedEchoHandler implements Runnable { private Socket incoming; private int i; ThreadedEchoHandler(Socket incoming, int i) { this.incoming = incoming; this.i = i; } public void run() { // TODO Auto-generated method stub try { try { InputStream is = incoming.getInputStream(); OutputStream os = incoming.getOutputStream(); Scanner in = new Scanner(is); PrintWriter out = new PrintWriter(os, true); out.println("Hello! Enter BYE to exit!"); boolean done = false; while (!done && in.hasNextLine()) { String line = in.nextLine(); out.println("Echo: " + line); if (line.trim().equals("BYE")) done = true; } } finally { incoming.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
------解决方案--------------------
看看你的MyThread类有没有类似MyThread(Socket s, int n); 这样的构造方法
------解决方案--------------------
又是线程..和加载的问题,.~~
------解决方案--------------------
没有那样的构造方法,那有什么样的构造方法?你按照那个构造方法new就行了
------解决方案--------------------
^_^ 路过 ^_^