1 下载Jmeter
https://mirror-hk.koddos.net/apache//jmeter/
2 开启Jmeter
3 添加线程组
4添加 TCP sampler
5添加View Tree
设置1个线程不断循环
6设置线程组
7设置Tcp sampers
设置eolvalue=9,十进制,当tcp sampler 接收到服务器回复字节9的时候,开启下一次循环。发送21,539 字节。
8开启测试
点击绿色三角形开始发送,点stop六边型停止
9服务器端java代码入下
package com.suncreate.testSocket;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.*;
import java.util.Arrays;
public class SocketServer {
public static void main(String[] args) throws Exception {
// 监听指定的端口
int port = 55533;
ServerSocket server = new ServerSocket(port,50, InetAddress.getByAddress(new byte[]{(byte)172,16,37,(byte)162}));
System.out.println("waiting");
Socket socket = server.accept();
// 建立好连接后,从socket中获取输入流,并建立缓冲区进行读取
InputStream inputStream = socket.getInputStream();
OutputStream outputStream=socket.getOutputStream();
byte[] bytes = new byte[1024];
int len=0,total=0;
long second=0,start=System.currentTimeMillis();
while ((len = inputStream.read(bytes)) != -1) {
System.out.println(len);
total+=len;
second= (System.currentTimeMillis()-start)/1000;
if(second!=0)
System.out.println(total/second);
System.out.println("----------------------------------------");
outputStream.write(new byte[]{1,2,3,4,5,6,7,8,0x09});
outputStream.flush();
}
outputStream.close();
inputStream.close();
socket.close();
server.close();
}
}
10服务器输出如下
1024
24643128
----------------------------------------
1024
24643242
----------------------------------------
1024
24643356
----------------------------------------
1024
24643470
----------------------------------------
1024
24643584
----------------------------------------
1024
24643697
----------------------------------------
1024
24643811
----------------------------------------
1024
24643925
----------------------------------------
1024
24644039
----------------------------------------
1024
24644152
----------------------------------------
1024
24644266
----------------------------------------
1024
24644380
----------------------------------------
1024
24644494
----------------------------------------
1024
24644608
----------------------------------------
1024
24644721
----------------------------------------
1024
24644835
----------------------------------------
1024
24644949
----------------------------------------
1024
24645063
----------------------------------------
1024
24645176
----------------------------------------
1024
24645290
----------------------------------------
1024
24645404
----------------------------------------
1024
24645518
----------------------------------------
1024
24645632
----------------------------------------
1024
24645745
----------------------------------------
1024
24645859
----------------------------------------
1024
24645973
----------------------------------------
1024
24646087
----------------------------------------
1024
24646200
----------------------------------------
1024
24646314
----------------------------------------
1024
24646428
----------------------------------------
1024
24646542
----------------------------------------
1024
24646656
----------------------------------------
1024
24646769
----------------------------------------
1024
24646883
----------------------------------------
1024
24646997
----------------------------------------
1024
24647111
----------------------------------------
1024
24647224
----------------------------------------
1024
24647338
----------------------------------------
1024
24647452
----------------------------------------
1024
24647566
----------------------------------------
1024
24647680
----------------------------------------
1024
24647793
----------------------------------------
1024
24647907
----------------------------------------
1024
24648021
----------------------------------------
1024
24648135
----------------------------------------
1024
24648248
----------------------------------------
1024
24648362
----------------------------------------
1024
24648476
----------------------------------------
1024
24648590
----------------------------------------
1024
24648704
----------------------------------------
1024
24648817
----------------------------------------
1024
24648931
----------------------------------------
1024
24649045
----------------------------------------
1024
24649159
----------------------------------------
1024
24649272
----------------------------------------
1024
24649386
----------------------------------------
1024
24649500
代码修改:
package com.suncreate.testSocket; import io.netty.util.concurrent.Promise; import io.netty.util.concurrent.SingleThreadEventExecutor; import java.io.InputStream; import java.io.OutputStream; import java.net.*; import java.util.Arrays; import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.ThreadFactory; public class SocketServer2 { public static void main(String[] args) throws Exception { // 监听指定的端口 int port = 55533; ServerSocket server = new ServerSocket(port,50, InetAddress.getByAddress(new byte[]{(byte)172,16,37,(byte)162})); // SocketAddress socketaddress=new InetSocketAddress("172.16.37.162"); // server.bind(socketaddress); // server将一直等待连接的到来 System.out.println("server将一直等待连接的到来"); Socket socket = server.accept(); // 建立好连接后,从socket中获取输入流,并建立缓冲区进行读取 InputStream inputStream = socket.getInputStream(); OutputStream outputStream=socket.getOutputStream(); // 必须 byte[] bytes = new byte[1024*10]; int len=0,total=0; long second = 0, start = System.currentTimeMillis(); while(true) { while ((len = inputStream.read(bytes)) != -1) { total += len; System.out.println("------------------"); if(total>14785*3-100) break; } System.out.println("++++++++++++++++++"); second = (System.currentTimeMillis() - start) / 1000; outputStream.write(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 0x09}); outputStream.flush(); if(second!=0) { System.out.println(second); System.out.println(total); System.out.println(total / second); } } } }
++++++++++++++++++
19
1641802368
86410650
------------------
++++++++++++++++++
19
1641812608
86411189
------------------
++++++++++++++++++
19
1641822848
86411728
------------------
++++++++++++++++++
19
1641833088
86412267
------------------
++++++++++++++++++
19
1641843328
86412806
------------------
++++++++++++++++++
19
1641853568
86413345
------------------
++++++++++++++++++
19
1641863808
86413884
------------------
++++++++++++++++++
19
1641874048
86414423
------------------
++++++++++++++++++
19
1641884288
86414962
------------------
++++++++++++++++++
19
1641894528
86415501
------------------
++++++++++++++++++
19
1641904768
86416040
------------------
++++++++++++++++++
19
1641915008
86416579
------------------
++++++++++++++++++
19
1641925248
86417118
------------------
++++++++++++++++++
19
1641935488
86417657
------------------
++++++++++++++++++
19
1641945728
86418196
------------------
++++++++++++++++++
19
1641955968
86418735
------------------
++++++++++++++++++
19
1641966208
86419274
------------------
++++++++++++++++++
19
1641976448
86419813
------------------
++++++++++++++++++
19
1641986688
86420352
------------------
++++++++++++++++++
19
1641996928
86420890
------------------
++++++++++++++++++
19
1642007168
86421429
------------------
++++++++++++++++++
19
1642017408
86421968
------------------
++++++++++++++++++
19
1642027648
86422507
------------------
++++++++++++++++++
19
1642037888
86423046
------------------
++++++++++++++++++
19
1642048128
86423585
------------------
++++++++++++++++++
19
1642058368
86424124
------------------
++++++++++++++++++
19
1642068608
86424663
------------------
++++++++++++++++++
19
1642078848
86425202
------------------
++++++++++++++++++
19
1642089088
86425741
------------------
++++++++++++++++++
19
1642099328
86426280
------------------
++++++++++++++++++
19
1642109568
86426819
------------------
++++++++++++++++++
19
1642119808
86427358
https://testerhome.com/topics/2006
https://www.cnblogs.com/bf-blackfish/p/10579867.html
https://www.cnblogs.com/chenyun-/p/11714634.html
https://www.cnblogs.com/bf-blackfish/p/10579867.html
https://www.cnblogs.com/landhu/p/5488807.html