标签:tst edr 获取 system ack buffere 发送 import lin
客户端:数据来自于键盘录入,直到输入的数据是886,发送数据结束
服务器:接收到的数据在控制台输出
package com.inetTes01; /* 客户端:数据来自于键盘录入,直到输入的数据是886,发送数据结束 */ import java.io.*; import java.net.Socket; public class ClientDemo01 { public static void main(String[] args) throws IOException { //创建客户端Socket对象 Socket s = new Socket("192.168.18.6", 10000); // 数据来自于键盘录入,直到输入的数据是886,发送数据结束 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //封装输出流对象 BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream())); String line; while ((line = br.readLine()) != null) { if("886".equals(line)) { break; } // //获取输出流对象 // OutputStream os = s.getOutputStream(); // os.write(line.getBytes()); bw.write(line); bw.newLine(); bw.flush(); } //释放资源 s.close(); } }
package com.inetTes01; /* 服务器:接收到的数据在控制台输出 */ import java.io.*; import java.net.ServerSocket; import java.net.Socket; public class ServerDemo01 { public static void main(String[] args) throws IOException { //创建服务器Socket对象 ServerSocket ss = new ServerSocket(10000); while (true) { //监听客户端的连接返回一个对应的Socket对象 Socket s = ss.accept(); //获取输入流 // InputStream is = s.getInputStream(); // InputStreamReader isr = new InputStreamReader(is); // BufferedReader br = new BufferedReader(isr); BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream())); String line; while ((line = br.readLine())!= null) { System.out.println(line); } } //ss.close(); } }
标签:tst edr 获取 system ack buffere 发送 import lin
原文地址:https://www.cnblogs.com/lsswudi/p/11440399.html