日期:2014-05-20 浏览次数:20914 次
package org.exam4; import java.net.*; import java.io.*; public class T4Server { public static void main(String[] args) throws Exception { ServerSocket server = new ServerSocket(5678); while (true) { Socket s = server.accept(); MyThread t = new MyThread(s); t.start(); } } } class MyThread extends Thread { Socket s; public MyThread(Socket s) { this.s = s; } public void run() { BufferedReader in; try { in = new BufferedReader(new InputStreamReader(s.getInputStream())); PrintWriter out = new PrintWriter(s.getOutputStream(), true); String line = null; while ((line = in.readLine()) != null) { out.println("Receive"); } s.close(); } catch (IOException e1) { e1.printStackTrace(); } } }