Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

seiji9's avatar

Socket io chat server

I am building a chat server in socket io with express. I want to implement block user feature. A user can have multiple sockets if they are logged in from multiple devices. How do I prevent a user (userA) from sending messages to the other user (userB) https://xender.vip/ , if userB blocks userA after the socket connection is already established for userA and userB and more importantly the block should work for multi node socket server as well.

0 likes
1 reply
josshry34's avatar

As i know maintain a data structure to store the list of blocked users for each user. This data structure can be a key-value store, such as a database or an in-memory cache. When a user (userB) wants to block another user (userA), update the blocked user list for userB by adding userA to the list. https://www.myccpay.me/ This update should happen in the database or cache. In your socket.io server, before sending a message from userA to userB, check if userB has blocked userA. You can do this by querying the blocked user list for userB.

Please or to participate in this conversation.