日期:2014-05-20 浏览次数:21052 次
/*服务器端*/ public class TCPServer { public static void main(String[] args) throws Exception { ServerSocket ss = new ServerSocket(6666); while (true) { Socket s = ss.accept(); System.out.println("A socket has connected!"); } } }
/*客户端*/ public class TCPClient { public static void main(String[] args) throws Exception { Thread.sleep(1000); Socket s = new Socket("127.0.0.1", 6666); } }