B
B
belyy_lis2021-02-09 13:46:06
React
belyy_lis, 2021-02-09 13:46:06

What is the fastest and easiest way to connect client and server on local machine in JS?

Hello everybody! My conscience began to gnaw at me for the lack of skill and understanding of how everything works in general, so I decided to ask. I have a React app inside Electron.

The task is as follows:
I want to make custom system buttons for minimizing, maximizing and closing the application.

And I have already achieved this goal, but it seems to me through a crutch. I'm using socket.io on a server* (in Node.js) and handling events that happen on socket.ioo-client in a React app. This allows you to control any external functions of Electron without problems. Roughly speaking: the site controls the browser through sockets.

But it seems to me somehow wrong, although everything works instantly. Like one machine, why these crutches with sockets.

Is there a better and faster way? Or am I just overthinking?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Ineshin, 2021-02-09
@IonDen

In general, nothing so terrible.
But remember one difference:
Sockets are needed in order to maintain a continuous connection between the client and the server. Eliminate the transfer of unnecessary data and increase the response time. For your task, this is a bit overkill.
When you press the buttons - only at this moment you need to send data to the server. This task is easier to handle with regular queries such as fetch or libraries like axios.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question