FG
📡 Networking

Target specific client on clustered socket.io server and using acknowledgment callback

Freshalmost 4 years ago
Mar 14, 20260 views
Confidence Score88%
88%

Problem

I've clustered my socket.io server and I'm looking for a way to emit to a specific client and receiving a acknowledgment callback. The problem that the server doesn't have a reference to a instance of the target client, because this client can be connected to another socket.io server instance (because it's clustered). I know I can emit to a room named after the the socket.id or a custom room where I put the client in. But the problem is that this is considered broadcasting and then I can't use a acknowledgment callback. I don't want to add complexity to the target client. The target client should just be able to call the callback. I see two possible solutions: - Find a way to create a fake socket instance with the socket.id (so I can use existing callback code) - Broadcast to a room and build my own callback system, see: https://github.com/Automattic/socket.io/issues/1656#issuecomment-49077695 A fake socket instance wouldn't actually have a connection to a client, but I hope to use it's emit function, have it talk to it's adapter (socket.io-redis) and have it receive the acknowledgment callback. Any tips on these solutions, maybe something I should also consider.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate1 verificationLast verified Mar 14, 2026

Solution: Target specific client on clustered socket.io server and using acknowledgment callback

Low Risk

@FREEZX has been implementing the functionality to receive clients in rooms (even over multiple node instances, see: https://github.com/Automattic/socket.io/pull/1630 https://github.com/Automattic/socket.io-adapter/pull/5 https://github.com/Automattic/socket.io-redis/pull/15 But even then I need a way to emit to a specific client and get my callback called. Guille: Update: we're making a minor r

84

Trust Score

1 verification

100% success
  1. 1

    @FREEZX has been implementing the functionality to receive clients in rooms (eve

    https://github.com/Automattic/socket.io/pull/1630 https://github.com/Automattic/socket.io-adapter/pull/5 https://github.com/Automattic/socket.io-redis/pull/15 But even then I need a way to emit to a specific client and get my callback called.

  2. 2

    Guille: Update: we're making a minor release 1.1.1 with bugfixes, and .clients(f

    Guille: Update: we're making a minor release 1.1.1 with bugfixes, and .clients(fn) should be in the next one 1.2.0

Validation

Resolved in socketio/socket.io GitHub issue #1811. Community reactions: 0 upvotes.

Verification Summary

Worked: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

socket.iowebsocketrealtimeenhancement