所以,我有TCP套接字服务器,它定义了基于文本的客户端服务器通信 . 我想使用jmeter的TCP采样器测量这项服务的性能,但问题是我找不到为每个请求发送EOL字节的方法 . 从我看到的服务器定义“\ 0”作为行分隔符 . 根据我的理解,字段“行尾(EOL)字节值”用于解析服务器响应,并且在请求时不考虑其值 .
使用以下代码,我能够连接到我的服务器并正确解析行分隔符:
NioSocketConnector connector = new NioSocketConnector();
TextLineCodecFactory customTextLineCodecFactory = new TextLineCodecFactory(Charset.forName("UTF-8"),
LineDelimiter.NUL, LineDelimiter.NUL);
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(customTextLineCodecFactory));
connector.setHandler(this);
IoSession session;
for (;;) {
try {
ConnectFuture future = connector.connect(new
InetSocketAddress("127.0.0.1", 8090));
future.awaitUninterruptibly();
session = future.getSession();
break;
} catch (RuntimeIoException e) {
System.err.println("Failed to connect");
e.printStackTrace();
Thread.sleep(5000);
}
}
// wait until the summation is done
session.write("sth");
session.getCloseFuture().awaitUninterruptibly();
connector.dispose();
我正在使用 Apache Mina 库进行套接字通信 .
使用TCP Sampler我连接到我的服务器,但是没有发送行分隔符,服务器也不知道数据包的结束位置 .
我的问题是:如何使用TCP Sampler的默认TCPClientImpl发送行结束字节?
1 回答
在TCP Sampler中设置属性:
或者如果是在Java代码中:
...这将强制你的字符串EOL为 NULL Strings
在下面你可以看到屏幕右侧的EOL字节值 .