关于输入流关闭的问题。。
以下是服务端代码
import java.net.*;import java.io.*;public class Server{ private ServerSocket ss; private Socket socket; public Server(){ try{ ss = new ServerSocket(10000); while(true){ socket = ss.accept(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); String string = br.readLine(); bw.write(string,0,string.length()); br.close(); bw.close(); socket.close(); } } catch(IOException e){ System.err.println(e.toString()); } } public static void main(String args[]){ new Server(); }}
import java.net.*;import java.io.*;import javax.swing.*;public class Client{ private Socket socket; public Client(){ try{ while(true){ socket = new Socket("127.0.0.1",10000); BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream())); String string = br.readLine(); System.out.println(string); br.close(); socket.close(); } } catch(IOException e){ System.err.println(e.toString()); } } public static void main(String args[]){ new Client(); }}