background

Recently, I am working on a game project, so I need to debug the Websock service locally and transfer it in binary form. Most of the test pages on the Internet are in text form, so it does not meet the requirements. In order to solve the binary transmission of websocket, and implement the heartbeat problem of webSocket communication mechanism, so a practice is written.

purpose

  1. Jmeter establishes a connection with the Java back-end WebSocket service
  2. Due to the Websocket mechanism, Jmeter is required to periodically check whether the connection is stored or not. Otherwise, the connection will be disconnected when the heartbeat time expires.
  3. After establishing the connection, binary transfer

To share with you the Internet scene design and architecture design scheme digging gold: Underground Collection Kelvin juejin.cn/user/104639…

operation

1. Download the Jmeter

Jmeter.apache.org/download_jm… Go to the official website to find the latest version and find a zip file for easy decompression in Windows. After decompressing, find the jmeter.bat file in the bin directory and start JMeter

2. Change the language

Click menu bar -option-language-Chinese to display Chinese

3. Download the Jmeter Websocket plug-in

Bitbucket.org/pjtr/jmeter… Once downloaded, place it under lib\ext in the JMeter directory and restart JMeter

Such as: D: \ \ Program Files \ apache jmeter – 5.2.1 \ lib \ ext \

4. Create a thread group

5. Create a WebSocket write sample

Right-click on the thread group – “Add -” “Sampler -” websocket Simple Write sample

5.1 Creating a Connection

Enter the IP address, port number, and connection path.

Note that this is only used to create a connection to the server, and is not really used to transmit data. Websockets are created after the actual transmission of communication, such as: chat room to establish a room later communication.

5.2 Creating a View Result Tree

Used to see if there is a successful connection for each communication. Right-click on the sample – add – Listener – to see the result tree

6. Create a real communication websocket write sample

Also in a thread group, create a WebSocket write sample. In this case, you do not need to enter the IP address and port number. You only need to select an existing connection.

6.1 Filling in and Transmitting binary

You can’t fill in json directly. You have to write an object, convert it to a byte array, and then convert it to a hexadecimal number and put it into JMeter.

My two classes, a protobuf software proto.exe generated from the class, there is a conversion to toByteArray method, get a binary array, and then write a tool to just convert the array to hexadecimal, get the result.

After execution, print out the number and put it in the jMeter parameter field. Parameter type, remember to select Binary


So we’re almost done here. In order to pressure test, we need to perform heartbeat maintenance on the Websocket back end.

7. Finally, get a timed heartbeat

Right-click on the thread group – “Add -” “Logical Controller -” RunningTime controller

Fill in this timed task survival time

7.1 Creating Heartbeat Transmission Content

As in point 6, create a WebSocket write sample to transfer binary data.

7.2 Creating a Fixed Timer

Fill in the timer every number of seconds.

That’s the end of this article. This explanation is websocket development self-test, may not be used for most Java development, only the game students learn to use websocket, make games, chat rooms, websocket and other projects of the students to call it.


Welcome to pay attention to the public number, the article faster step

My public account: Tibet thinking

Nuggets of gold: Hide Kelvin

Jane: Hide Kelvin

My Gitee: Underground Collection Kelvin gitee.com/kelvin-cai