Why can't I send non-stringified objects using WebSockets (ws package)?

125
June 22, 2019, at 02:10 AM

Made a websocket server, I was wondering why you can't send non-stringified objects over the socket connection. I understand you can use JSON.stringify() but I am curious as to why the data gets turned into a Blob if you just send something like an array, and why it causes errors in the server if you try sending a key/value pair object.

Here's what the client receives in the event.data if the server sends a non-stringified array with 3 objects (relevant code is underneath): https://media.discordapp.net/attachments/559635624806580235/591322984199880715/unknown.png

Server code:

ws.send(['setup',1,2]);

Client code:

ws.addEventListener('message',function(e){
    const data = e.data;
    console.log(data);
});

So why do I get a Blob? And why specifically a Blob when using websockets? And are there any good resources which can teach me how websockets work?

Rent Charter Buses Company
READ ALSO
Find Documents whose Subdocument Fields partially match given Criteria with Mongoose

Find Documents whose Subdocument Fields partially match given Criteria with Mongoose

I have using nodeJS and mongoose/mongoDB to build an APIConsider the following model for a generic Model (Gmodel):

134
I have a send Korean and Japanese values from rest api in a get request

I have a send Korean and Japanese values from rest api in a get request

I have to send Korean and Japanese values from rest api in a get requestwhen I am trying to fetch param in my node code ,I am getting different encoded value ,I need proper Korean value in my node code so that I can use it for other operation

150
How to properly store clientId, client secret and OAuth2 token with ReactApp

How to properly store clientId, client secret and OAuth2 token with ReactApp

I'm building an App which I use ReactJS to build my Client-side and Spring framework for my Server-side setupWhat I'm trying to archive is a way to store my ClientId, Client secret and OAuth token since I'm implementing OAuth2 Security on my Server-side

87
Trying to output several images with different breakpoints (2000w, 1200w, … ) using streams and sharp

Trying to output several images with different breakpoints (2000w, 1200w, … ) using streams and sharp

I have a folder inside src/images/original The nodejs script is inside the root directoryThe output should be src/images/processed

104