本帖最后由 freehello 于 2015-9-1 13:32 编辑
- import java.net.*;
- import java.io.*;
- //客户端
- public class Client { //代码很乱只为测试
-
- public static void main(String[] args) throws Exception{
-
- Socket socket = new Socket("127.0.0.1",10000);
- PrintWriter pw = new PrintWriter(socket.getOutputStream());
- BufferedReader bufr = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- pw.write("hello");
- pw.flush();
- String data = "";
- data = bufr.readLine();
- System.out.println(data);
- pw.close();
- socket.close();
- bufr.close();
- }
-
- }
复制代码
- import java.net.*;
- import java.io.*;
- //服务器端
- public class Server { //代码很乱只为测
-
- public static void main(String[] args) throws Exception{
-
- ServerSocket s = new ServerSocket(10000);
- Socket socket = s.accept();
- PrintWriter pw = new PrintWriter(socket.getOutputStream());
- BufferedReader bufr = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- String data = "";
- data = bufr.readLine();
-
- System.out.println(data);
- pw.write("hello");
- pw.flush();
- pw.close();
- socket.close();
- s.close();
- bufr.close();
-
- }
- }
复制代码
无法通信都堵塞在了readLine,求原因 |
|