- 论坛徽章:
- 0
|
服务器端应该是用.net写的
我客户端去读取数据
代码段1:- BufferedReader in = new BufferedReader(new InputStreamReader(
- socket.getInputStream()));
- int n = 0;
- while ((n = in.read()) > 0) {
- char c = (char)n;
- System.out.print((char) n);
- }
- System.out.println("end");
复制代码 代码段2:- DataInputStream in = new DataInputStream(socket.getInputStream());
- byte[] buf = new byte[1024];
- int len = 0;
- while ((len = in.read(buf)) != -1) {
- String text = new String(buf, 0, len);
- System.out.print(text);
- }
复制代码 这两段代码 都能读取到服务端发来的数据
但是最后都会阻塞,程序不能结束!!
应该怎么处理呢?让程序读完数据后 退出程序?? |
|