哥们 你server接受数据那 有问题 具体 没有找到 你的程序跑到while循环就死了 帮你改了下 这样就行了 public class TcpSever { /** * @param args * @throws IOException */ public static void main(String[] args) { try { ServerSocket ss = new ServerSocket(5000); System.out.println("我等待连接!"); Socket socket = ss.accept(); InputStream is; is = socket.getInputStream(); OutputStream os = socket.getOutputStream(); byte[] buffer = new byte[11]; int length = 0; length = is.read(buffer, 0, buffer.length); String str = new String(buffer, 0, length); System.out.println("server接受到的数据="+str); System.out.println("server开始发送数据!!"); os.write("welcome".getBytes()); is.close(); os.close(); //socket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public class TcpClient { /** * @param args * @throws IOException * @throws UnknownHostException */ public static void main(String[] args) { try { Socket socket = new Socket("127.0.0.1", 5000); OutputStream os = socket.getOutputStream(); InputStream is; is = socket.getInputStream(); System.out.println("我开始发送!"); os.write("hello world".getBytes()); System.out.println("我在等待接受数据!"); byte[] buffer = new byte[7]; int length = 0; length = is.read(buffer, 0, buffer.length); String str = new String(buffer, 0, length); System.out.println("client接收到的数据是="+str); is.close(); os.close(); //socket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }