服务器端响应客户的报了差
java.net.SocketException: Socket input is shutdown at java.net.Socket.getInputStream(Socket.java:907) at com.imooc.socke.Client.main(Client.java:27) 我报这个错是什么回事,我反照老师的代码写的服务器端响应客户的
java.net.SocketException: Socket input is shutdown at java.net.Socket.getInputStream(Socket.java:907) at com.imooc.socke.Client.main(Client.java:27) 我报这个错是什么回事,我反照老师的代码写的服务器端响应客户的
2017-02-08
//1.创建客户端Socket,指定服务器地址和端口
Socket socket = new Socket("localhost", 8888);
//2.获取输出流,向服务器端发送信息
OutputStream os = socket.getOutputStream();//字节输出流
PrintWriter pw = new PrintWriter(os);//将输出流包装为打印流
pw.write("用户名:admin;密码:123");
pw.flush();
//3.获取输入流,并读取服务器端的响应信息
socket.shutdownOutput();
InputStream is = socket.getInputStream();
BufferedReader br = new BufferedReader(
new InputStreamReader(is));//字节流包装成字符流并添加缓冲
String info = null;
while((info = br.readLine()) != null){
System.out.println("我是客户端,客户端说:"+info);
}
client类中把socket.shutdownInput();写成了这个
举报