ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ package com.youge.nio.zerocopy; import java.io.DataInputStream; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; /** * 传统的IO传输读写数据 * @author: hcf * @qq: 46914685 * @email: 46914685@qq.com * @date: 2020/11/27 10:52 */ public class OldIOServer { public static void main(String[] args) throws IOException { ServerSocket serverSocket = new ServerSocket(7001); while (true) { Socket socket = serverSocket.accept(); DataInputStream dataInputStream = new DataInputStream(socket.getInputStream()); try { byte[] byteArray = new byte[4096]; while (true) { int readCount = dataInputStream.read(byteArray, 0, byteArray.length); System.out.println(readCount); if (readCount == -1) { break; } } }catch (Exception e){ e.printStackTrace(); } } } } ~~~