如何在JMeter中创建TCP/IP API以实现自动化与负载测试?
How to Create a TCP/IP API Test in JMeter for Your Request
Here's a step-by-step, practical guide to set up JMeter for sending your JSON payload to the TCP server at 10.10.xx.xxx:4433—perfect for both automation and load testing:
1. Build the Core Test Structure
- Open JMeter and create a new Test Plan (File > New).
- Right-click the Test Plan > Add > Threads (Users) > Thread Group. Configure this based on your testing goals:
- Number of Threads (Users): The number of concurrent requests you want to simulate.
- Ramp-Up Period: Time (in seconds) to spin up all threads (e.g., 10 seconds for 10 users = 1 user per second).
- Loop Count: How many times each thread will repeat the request (set to "Forever" for continuous load testing).
2. Add and Configure the TCP Sampler
Right-click your Thread Group > Add > Sampler > TCP Sampler. This is where you’ll define the connection and payload:
Critical TCP Sampler Settings:
- Server Name or IP: Enter
10.10.xx.xxx(replace thexxwith your actual IP segments). - Port Number:
4433 - Text to send: Paste your full JSON payload here. Important: TCP is a stream protocol, so you must include a delimiter the server recognizes to mark the end of the message. Common options:
- Append
\r\n(carriage return + newline) at the end of your JSON. - If the server uses a specific delimiter (like a null byte
\0), add that instead (check server docs or use Wireshark to confirm if unsure).
- Append
- Re-use connection: Check this box for load testing to keep connections alive between requests—this boosts performance and mimics real-world traffic better.
- SSL: If the TCP server uses SSL/TLS encryption, check this box. For custom keystores, go to Options > SSL Manager to configure credentials first.
3. Add Listeners to Analyze Results
To validate requests and measure performance:
- Right-click the Thread Group > Add > Listener > View Results Tree: This lets you inspect each request/response in detail (ideal for debugging).
- Add listeners like Summary Report or Aggregate Graph for load testing metrics: throughput, average response time, error rates, etc.
4. Optional: Dynamic Data Handling
If fields like REQDT (timestamp) need to be dynamic, use JMeter’s built-in functions:
- Replace the static
REQDTvalue with${__time(ddMMyyyyHHmmss,)}to generate the current timestamp in the formatddMMYYYYHHmmss(matches your example15052018110916). - For other dynamic values, use a CSV Data Set Config to read from a file, or a JSR223 PreProcessor to modify the payload programmatically (e.g., using Groovy).
5. Test and Troubleshoot
- Click the green Run button to execute the test.
- In the View Results Tree:
- A successful response means your setup works.
- If you get errors, check these common issues first:
- Incorrect delimiter (server isn’t detecting the end of the message).
- SSL not enabled when required.
- Network connectivity issues to
10.10.xx.xxx:4433. - Typos in the JSON payload.
Once validated, you can scale the Thread Group settings to simulate higher load or add more samplers for multi-step scenarios.
内容的提问来源于stack exchange,提问作者Sanjeev Bhasker
相关产品推荐
相关产品推荐

