P
P
postya2020-11-05 14:15:49
Node.js
postya, 2020-11-05 14:15:49

In what form is it better to transfer data from a websocket server?

I have one project at once for the server and for the client. The server part is in a separate server folder.
I need to send data and receive on the client
. The client will be a Vue JS application.
The server will have many methods that will send data in different categories. For example, one method sends numbers by temperature, another - by air humidity, the third - by pressure

An example of one of the methods:

function getRandomValue(){
  return Math.floor(Math.random() * (50 - 5 + 1)) + 5;
}
io.on("connection", socket => {
  setInterval(() => {
    socket.broadcast.emit("newData", getRandomValue())
  }, 1000)
});


What is the best way to send data to the client?
Make one big json object?
Or maybe it is somehow possible to transfer separate methods with data on different streams?
Please tell me the best options

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question