public static void main(String[] args) throws IOException { //1.创建客户端Socket对象 Socket socket = new Socket("192.168.200.1",8802); //2.发送数据 OutputStream os = socket.getOutputStream(); os.write("你好,TCP,我来了".getBytes(StandardCharsets.UTF_8)); //3.释放资源 socket.close(); }
public static void main(String[] args) throws IOException { //1.创建ServerSocket并监听端口号 ServerSocket ss = new ServerSocket(8802); //2.监听客户端请求 Socket s = ss.accept(); //3.接受数据 InputStream is = s.getInputStream(); byte[] bys = new byte[1024]; int len = is.read(bys); System.out.println(new String(bys,0,len)); //4.释放资源 ss.close(); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)