简体   繁体   中英

Multiple instances of socket using Socket.io

In a part of my web app there are items with detailed notes that can be edited by several people at once. This was causing issues so I decided to implement socket.io so that changes would be pushed in real time. It is working great. The issue is that I am using the same socket for all notes. If two people are editing two different notes, I would expect them to use different sockets. I don't even know how to search this issue. I would imagine each socket is unique by note ID. Any suggestions?

There's no need to use a separate socket for editing a different note. When you send an edit for a note, you can just send an id for the note with the edit so that when a server receives an edit, it knows exactly which note the edit belongs to.

If you want more specific help, you will have to show us your actual code.

If two people are editing two different notes, I would expect them to use different sockets.

That is not required and is probably not desirable either. You can send messages retaining to many different notes over the same socket. A socket is merely a communications channel. It doesn't have to be tied to a specific piece of data. You just need to include with the message you are sending some sort of identifier so the recipient of the message knows which data this message pertains to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM