# Websocket with Apache JMeter

It’s apparent that the usage of Websocket has expanded greatly in recent years, and its reliability is expected to be high since it mostly carries crucial information to clients. Hence, [testing](https://loadium.com/blog/functional-testing-with-loadium-apache-jmeter/) their durability and reliability has become more important.

It is possible to execute [performance tests](https://loadium.com/blog/tag/performance-testing/) on Websockets with Apache [JMeter](https://loadium.com/blog/tag/jmeter/) by using “Websocket Samplers” plugin developed by Peter Doornbosch.

## **Websocket Samplers Plugin For Jmeter**

Let’s take a look at the [plugin](https://loadium.com/blog/how-to-install-use-jmeter-plugin/) first.&#x20;

You can download the plugin [here](https://jmeter-plugins.org/?search=websocket-samplers).

Once you install the plugin, you will get 7 new Sampler elements:

* **Websocket Close**: Closes the current Websocket connection
* **Websocket Open Connection:** Initiates a new connection with given parameters, with options for connection\&read timeouts
* **Websocket Ping/Pong:** Performs a ping or ping/pong service for the current connection
* **Websocket Sampler:** A single sampler that performs one-time request.
* **Websocket Single Read Sampler:** Reads response without sending a request.
* **Websocket Single Write Sampler:** Sends a request without reading the response
* **Websocket request-response Sampler:** Does both sending a request and reading response

## Example Case

Websockets’ behavior may reveal differences between each other, but the structure of a script for Websocket is usually similar to the following format:

* Initiating a connection with Websocket
* Sending the first request
* Receiving the first request
* Using a looper (Runtime controller or Loop Controller etc.) to continue the data transmission between the client and the server by sending a message and receiving it.

-First, we need to start a connection with the Websocket. It can be done either using “Websocket Open Connection”, or “Websocket Request” with the “setup new connection” option.

-The information about the sockets needs to be given. For example, you can find the socket’s information from Google Chrome’s Inspect mode>Network>WS

![](https://33973752-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUOy4kHWrKkuqX5mhH7%2F-Mch_kvN5vasPL15No-_%2F-MchdOwi_wB2kG1rUy6D%2Fimage.png?alt=media\&token=b451e504-1783-47b4-a826-3826e1dcc916)

-There is one another situation that requires a token that is received by another request for a Websocket to initiate a connection.

![](https://33973752-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUOy4kHWrKkuqX5mhH7%2F-Mche3jDlW_HwvC2RKQG%2F-McheVcMhdAL5dGW-sf9%2Fimage.png?alt=media\&token=358e68d1-55b0-4c20-b0f8-21d299c4d790)

-When the connection has started, there will be a series of messages that will be transferred from both the client and the server-side. Some of the requests going from the client might be unique, but at some point, repetitive pattern requests can be seen and it will be imitated with a loop logic. Additionally, this repetitive pattern usually has a constant interval between requests, which might need to be taken into account.

![](https://33973752-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUOy4kHWrKkuqX5mhH7%2F-Mche3jDlW_HwvC2RKQG%2F-McheeGvKEgn5tsebxwa%2Fimage.png?alt=media\&token=571563c6-2c35-48b0-8633-49da2187e81b)

That's it, happy testing!

{% content-ref url="../create-test/jmeter-test" %}
[jmeter-test](https://wiki.loadium.com/create-test/jmeter-test)
{% endcontent-ref %}

If you don't see the answer to your question here, please [reach out to us](https://loadium.com/contact-us/) to let us know! We're always improving our documentation.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.loadium.com/jmeter-corner/websocket-with-apache-jmeter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
