Websocket keys

Issue #86 closed
Rajesh Khanna created an issue

Hi Peter,

Does this keys play a vital role in the websocket connection.

If yes, How can we generate them manually for different requests,

Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==

Note: this keys are changing for each and every time and this keys gets change in the next request also

Request Header :

GET /chat HTTP/1.1 Host: example.com:8000 Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Sec-WebSocket-Version: 13

Response Header:

HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=

Comments (13)

  1. Peter Doornbosch repo owner

    Hi Rajesh,

    Yes it does, but you don't have to do anything with it; this is all handled by the plugin.

    When the client sets up the websocket connection, it generates a random value for the Sec-WebSocket-Key header and the server performs a small computation with this value and returns the result in the Sec-WebSocket-Accept header, as required by the websocket protocol specification, see https://tools.ietf.org/html/rfc6455#section-1.3.

    There is no need to generate them manually and the fact that the values are different for each websocket connection setup is mandated by the specification.

    Do not confuse these headers with authentication, it has nothing to do with that.

    Hth, Peter

  2. Rajesh Khanna reporter

    Thanks Peter for the info .

    Usually for running the script for multiple times , we have to corelate this Dynamic key value right? Because this key value is changing for each and every time and this key value also gets changed in the second request. So with the Websocket plugin , in the header we have to send the key values over there, right? how can we correlate them , usually if this values get passes in the above request response we can correlate them easily, but this value is not getting generated.

    Questions: Can we send the same value every time in the header ? Is this key main in establishing the websocket connection ? How can we generate them and pass them in the header ? Does this key value generates in any of the above request response (I have checked it , It didnt). OR NO need to pass this particular filed named Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== in the request header ?

    Cheers Rajesh N

  3. Peter Doornbosch repo owner

    Hi Rajesh,

    I don't understand your question. You don't have to do anything with this header. It is part of the websocket connection setup process, which the plugin handles for you completely. Whether you create one connection or one thousand, it doesn't matter, you don't have to script anything w.r.t. this header, the plugin handles it for you.

    Maybe, to understand what your after, it might help if you explain what you want to achieve. Why do want to manipulate these headers?

    Regards Peter

  4. Rajesh Khanna reporter

    Hi Peter,

    I am trying to open the connection of WSS://echo.websocket.org Screenshot1.png HTTP Header manager are copied from the developer tools(Network requests) of the application Screenshot2.png Screenshot3.png Here in the network requests form the appliaction , a key is getting passed eveytime and this key is getting changed everytime , So my doubt is something like “I am unable to connect to it because I am passing the existing key without changing it? ”

    Error: Websocket IO error Screenshot4.png

  5. Peter Doornbosch repo owner

    I wish you had started with one of the samples provided, because these show very clearly how to setup a simple test plan that connects with websocket.org (see sample test plans in https://bitbucket.org/pjtr/jmeter-websocket-samplers/src/master/samples/).

    From the HTTP Header Manager, remove the following headers (because they are part of the websocket connection setup and therefore handled by the plugin):

    • Connection
    • Upgrade
    • Host
    • Sec-WebSocket-Key
    • Sec-WebSocket-Version

    I can't hardly read the screenshots, but it seems you are getting a "connect timeout" error. This means you either made a mistake with hostname or port number, or a firewall is blocking access to the host. This error cannot be caused by incorrect headers, because when you have no connection with the server, the headers haven't been processed.

    Regards Peter

  6. sowkath ali

    you mean Sec-WebSocket-Key is not required in the hearder …i am getting error message socket connect is closed

  7. Peter Doornbosch repo owner

    There can be several reasons why the server is closing the connection; Sec-WebSocket-Key is not one of them.

  8. abdul bari

    it would be great if you share us the Reasons and also do i need to do any configuration modifications in jmeter property to use web socket connection ?

  9. Madan Mohan

    Hi @Peter Doornbosch , I am getting the below error while running the websocket through JMeter, May i know what did I miss here

    Can any one help me on this

  10. Log in to comment