💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
server ``` //1.创建ServerSocket对象,绑定端口,开始等待连接 ServerSocket ss = new ServerSocket(8888); //2.接收连接accept方法,返回socket对象 Socket socket = ss.accept(); //3.通过socket获取输入流 InputStream is = socket.getInputStream(); byte[] b = new byte[1024]; int len = is.read(b); String msg = new String(b, 0, len); //3.回复 OutputStream out = socket.getOutputStream(); out.write("你好".getBytes()); out.close(); is.close(); socket.close(); ss.close(); ``` client ``` Socket client = new Socket("localhost", 8888); OutputStream outputStream = client.getOutputStream(); outputStream.write("你好 服务器".getBytes()); outputStream.close(); InputStream inputStream = client.getInputStream(); byte[] b = new byte[1024]; inputStream.read(b); System.out.println(new String(b)); client.close(); ```