# custom ping-pong websocket heartbeating

**URL:** <https://community.gatling.io/t/custom-ping-pong-websocket-heartbeating/3254>\
**Category:** Gatling (Open-Source)\
**Created:** [September 8, 2016, 6:45pm UTC](https://community.gatling.io/t/custom-ping-pong-websocket-heartbeating/3254 "2016-09-08T18:45:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samuel\_Volin](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@Samuel\_Volin](https://community.gatling.io/u/Samuel_Volin)\
**Post date:** [September 8, 2016, 6:45pm UTC](https://community.gatling.io/t/custom-ping-pong-websocket-heartbeating/3254/1 "2016-09-08T18:45:17Z")

</div>

I’m using gatling to test our product using the websocket api. Things work pretty well with it, and so far we are seeing a lot of good results with Gatling. It’s pretty kickass!

That said, we want to point gatling at an older version of our product that used [socket.io](http://socket.io) v0.9, which used [a different heartbeat than ping-pong](https://github.com/socketio/socket.io/blob/0.9/test/parser.test.js#L153). It would “ping” with  
`2::`  
expecting back an identical`2::`  
as the “pong”.

We’re finding our websocket tests timeout when gatling doesn’t heartbeat back this way. I wanted to add this support in myself (and maybe make a code contribution).

I was looking at how gatling supported [ping-pongs in the first place](https://github.com/gatling/gatling/issues/2047), and I looked through [the pr that added the automatic pong reply to ping frames](https://github.com/gatling/gatling/pull/2194/files) . I’m not quite sure how it’s detecting a “ping” frame (or even how it’s responding “pong”). At this point I’m stumped and must ask: How would I go about modifying wsListener to support this custom heartbeating?

I understand Gatling 3.0 will be shipping with an updated websocket api. Is custom heartbeating (or custom automatic websocket responses) a feature that can be provided in the 3.0 release?  
At a minimum, how would I be able to modify gatling to support this specific heartbeating use-case?

Thanks for all of your help!

---

<div class="post-metadata">

**Author:** ![Samuel\_Volin](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@Samuel\_Volin](https://community.gatling.io/u/Samuel_Volin)\
**Post date:** [September 9, 2016, 5:43am UTC](https://community.gatling.io/t/custom-ping-pong-websocket-heartbeating/3254/2 "2016-09-09T05:43:01Z")

</div>

Sorry,  
I should mention I’m using **gatling v2.2.2,**  
and I don’t post to a google group often.

---

<div class="post-metadata">

**Author:** ![Samuel\_Volin](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@Samuel\_Volin](https://community.gatling.io/u/Samuel_Volin)\
**Post date:** [September 9, 2016, 10:09pm UTC](https://community.gatling.io/t/custom-ping-pong-websocket-heartbeating/3254/3 "2016-09-09T22:09:44Z")

</div>

I found a solution! I modified wslistener slightly so that when onMessage is triggered with the **2::** heartbeat it instead replies with a **2::** heartbeat.

`

// WebSocketTextListener  
def onMessage(message: String): Unit = {  
if (message == “2::”) {  
webSocket.sendMessage(“2::”)  
}  
wsActor ! OnTextMessage(message, nowMillis)  
}

`

It only took me all day. I’m leaving this here in case anyone else is curious on how to modify gatling to supply custom heartbeat requests.  
Thanks for making a great product!
