我需要一些帮助来使用消息的第一个字节来识别响应的长度。
当前使用 JMeter 发送一些 TCP 请求,但不幸的是它无法确定消息的结尾,因此它挂起。
通信协议(protocol)是Google Protobufs( Protocol Buffer ),并且没有用于确定消息结束的指示器。
下面是 Jmeter 的内容。如果有人能告诉我如何在此基础上构建,以便我可以使用响应的第一个字节来测量消息的长度,我将不胜感激。
JMETER - 读取方法。
public String read(InputStream is) throws ReadException {
ByteArrayOutputStream w = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[127];
int x = 0;
while ((x = is.read(buffer)) > -1) {
w.write(buffer, 0, x);
if (useEolByte && (buffer[x - 1] == eolByte)) {
break;
}
}
IOUtils.closeQuietly(w); // For completeness
final String hexString = JOrphanUtils.baToHexString(w.toByteArray());
if(log.isDebugEnabled()) {
log.debug("Read: " + w.size() + "\n" + hexString);
}
return hexString;
} catch (IOException e) {
throw new ReadException("", e, JOrphanUtils.baToHexString(w.toByteArray()));
}
}
最佳答案
首先阅读此内容:
然后,如果您要在协议(protocol)中发送一些指示行尾的自定义字符,请尝试在 jmeter.properties 中取消注释:
- tcp.eolByte=
如果您在消息开头发送长度,则使用:
如果这对您来说还不够,那么编写一个新的 ClientImpl 扩展 AbstractTCPClient .
问候
菲利普·M
关于java - 使用 JMeter TCP Sampler 是否可以使用响应的第一个字节来确定消息长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12428807/