S
S
squadbrodyaga2020-11-02 16:18:55
Node.js
squadbrodyaga, 2020-11-02 16:18:55

How to send a message to yourself on Socket.io?

Hello, I'm still learning how to use Socket.io and now I'm trying to make
registration form validation. The bottom line is, if a person entered a username that is
already in the database, then an error message is displayed to him.

But it turns out that the error message is displayed to everyone who is on the
registration page. Q: Does Socket.io have a method to send data to itself?

PS: Is it better to use Ajax for my task?
It’s just that I haven’t worked with Ajax yet, but Socket.io is quite satisfactory for me so far.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
squadbrodyaga, 2020-11-02
@squadbrodyaga

Found the answer. It turns out it's easy. Just io.emit()
write insteadsocket.emit()

D
Dr. Bacon, 2020-11-02
@bacon

But it turns out that the error message is displayed to everyone who is on the
registration page.

It's just that I haven't worked with Ajax yet, but Socket.io suits me quite well so far.

then forget about web sockets, you don’t need to sculpt them everywhere without understanding their work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question