A
A
Alexander Filippenko2018-03-06 09:26:45
Node.js
Alexander Filippenko, 2018-03-06 09:26:45

How to send data received via ajax request through Socket.io?

Good afternoon. It is necessary to open a modal in the browser on a signal from an external service. I decided to do it on sockets, the way is that when a POST request comes to a certain address, you need to determine which user to show the modal, and actually execute emit.
But I don't understand how to send data to the socket from the middle of the post request handler (I use express).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RidgeA, 2018-03-06
@RidgeA

Inside the POST handler, you need to somehow notify the socket handler to send a message.
Within the same process, this can be done using events - read about EventEmitter.
If the processes are different, then you need to notify differently. The first and simplest thing that came to mind was something like queues (RabbitMQ) or, more lightweight, Pub/Sub (Redis)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question