问啥我的不会打印信息
//1、创建一个服务器,绑定一个指定的端口 ServerSocket serverSocket = new ServerSocket(5555); //2、调用ServerSocket的accept方法,等待客户端连接 System.out.println("**********等待连接*********"); Socket socket = serverSocket.accept(); //3、获取输入流,读取客户端信息 InputStream is = socket.getInputStream(); BufferedReader isr = new BufferedReader( new InputStreamReader(is)); String str; while ((str = isr.readLine()) != null) { System.out.println("客户端:" + str); } socket.shutdownInput();//关闭输入流 //4、关闭资源 isr.close(); is.close(); socket.close(); System.out.println("连接关闭!"); //1、建立客户端Socket对象 Socket socket = new Socket("localhost", 5555); //2、获取输入流,向服务器请求登录 OutputStream os = socket.getOutputStream(); PrintWriter pw = new PrintWriter(os); pw.write("Gust:admin;Password:123"); socket.shutdownOutput(); //3、关闭相关资源 pw.flush(); pw.close(); os.close(); System.out.println("连接关闭!");
server端
*********等待连接*********
连接关闭!
client端
连接关闭!