Tag: 速度测试

Java网络文件传输问题

我正在编写一个可以测量本地网络速度的小型java程序。 这是我第一次使用套接字,但我已经整理了一个有效的程序。 唯一的问题是测量结果远非准确(方式太低)。 这是服务器代码: ServerSocket servsock = new ServerSocket(13267); while (true) { System.out.println(“Waiting…”); Socket sock = servsock.accept(); System.out.println(“Accepted connection : ” + sock); File myFile = new File(“test.txt”); FileInputStream in = new FileInputStream(myFile); OutputStream out = sock.getOutputStream(); int bytes = 0; byte[] buffer = new byte[8192]; int len; while ((len = in.read(buffer)) > 0) { […]