Websocket how send massive

Hello,

I try to send massive inside websocket, but catch 1007 error

socket.send(“[”{"eventId":"5435","marketId":"132","applicationType":"WEB"}“]”);

What the solution for it?

Thank you

Hi @LiliiaK,

I think you just need to fix your quoutes. You need to escape the inner " or just use template strings as in:

var ws = require("k6/ws");
var check = require("k6").check;

exports.default = function () {
    var url = "wss://echo.websocket.org"
    var params = {};

    var res = ws.connect(url, params, function (socket) {
        socket.on('open', function open() {
                socket.send(`[{"eventId":"5435","marketId":"132","applicationType":"WEB"}]`);
        });

        socket.on('message', function (msg) {
            console.log(msg);
            console.log(JSON.parse(msg)[0].marketId);
        });

        socket.setTimeout(function () {
            socket.close();
        }, 2000);
    });
}

This produces:

INFO[0001] [{"eventId":"5435","marketId":"132","applicationType":"WEB"}]
INFO[0001] 132

Thank you for answer. I spend all night but as a result it’s working when I escape all \

> socket.send('["{\\"eventId\\":\\"29990256\\",\\"marketId\\":\\"1.172636087\\",\\"applicationType\\":\\"WEB\\"}"]');

like this. Not sure why but working only in this way…

well the thing is that in this case what you are sending is an array which has a string inside instead of an object:

["this here is a string not a json object"]

instead of

[{"somekey": "value"}]

and it seems to me you want the second one …