Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't send json data over WebSocket (NODE JS)

After I created the .onopen event I made it launch some json data over, but I get an error,
Here is the code:

 ws.onopen = ('connect', function(connect) {
            let obj={};
            obj.name='data'
            message = 'connect';
            obj.body=message;
            var data = {"op": 0, "d": {"server_id": serverid, "user_id": author, "session_id": sessionid, "token": tokenn, "video": true, "streams": [
                {"type": "video", "rid": "100", "quality": -1}, {"type": "video", "rid": "50", "quality": 9223372036854775807}]}}, separators=(",", ":");

            ws.send(data.toString())


What I get:
node:events:368
throw er; // Unhandled ‘error’ event
^

Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:220:20)
Emitted ‘error’ event on WebSocket instance at:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use "JSON.stringify(data)" for convert Object to string

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading