Skip to content

feat: add targeted RPC delivery by client number#348

Merged
from2001 merged 6 commits intodevelopfrom
codex/add-rpcto-functionality-for-target-clients-j8m6gg
Feb 28, 2026
Merged

feat: add targeted RPC delivery by client number#348
from2001 merged 6 commits intodevelopfrom
codex/add-rpcto-functionality-for-target-clients-j8m6gg

Conversation

@from2001
Copy link
Collaborator

@from2001 from2001 commented Feb 26, 2026

Motivation

  • Provide the ability to send RPCs to specific clients instead of only broadcasting to the entire room.
  • Keep the API simple by unifying into Rpc() overloads rather than introducing a separate RpcTo() method.

Description

Unity Client:

  • Added NetSyncManager.Rpc(functionName, args, int targetClientNo) and Rpc(functionName, args, int[] targetClientNos) overloads. When no targets are given (or the array is empty), it falls back to broadcast.
  • Extended RPCMessage in DataStructure.cs with int[] targetClientNos field.
  • Updated BinarySerializer.cs to serialize/deserialize targets as count(1 byte) + clientNos(N × ushort) in the RPC frame.
  • Updated RPCManager with SendTo() internal method, preserving target info through the pending queue, size estimation, and offline loopback filtering.

Python Server:

  • Updated binary_serializer.py to serialize/deserialize targetClientNos in the RPC message.
  • Changed server.py _send_rpc_to_room(): when targetClientNos is non-empty, unicasts via ROUTER only to specified clients; otherwise broadcasts to the whole room.

Python Client API:

  • Added target_client_nos optional parameter to client.py rpc() method so Python clients can also send targeted RPCs.

Documentation:

  • Updated root CLAUDE.md and Unity CLAUDE.md to document RPC targeting capability.

Tests:

  • Added 8 round-trip tests in test_binary_serializer.py: broadcast, single target, multi-target, max 255 targets, overflow, None/missing treated as broadcast, UTF-8 function name.

Testing

  • pytest tests/test_binary_serializer.py — 8/8 RPC tests passed
  • black src/ tests/ && ruff check src/ tests/ && mypy src/ — all passed

Codex Task

@from2001
Copy link
Collaborator Author

We'll use #348

#286 #345 #346 #347 #348
Title Add targeted RPC transmission by ClientNo Add RpcTo targeted client delivery Add targeted RpcTo delivery API Add RpcTo targeted client delivery Add targeted RpcTo delivery by client number
Approach New MSG_RPC_TARGETED message type + ROUTER→DEALER direct delivery Encode targets in function name @target:1,2:Fn, filter in MessageProcessor Wrap as system RPC @system:rpc_to with JSON payload Encode targets in function name @target[1,2]|Fn, filter in OnRPCReceivedHandler Extend existing MSG_RPC binary format with targetClientNos field
Lines changed +2335 / -89 +93 / -4 +81 / -0 +106 / -0 +106 / -17
Files changed 15 3 (Unity) 1 (Unity) 2 (Unity) 6 (Unity + Python)
Server changes Yes (new message type + ROUTER delivery) None None None Yes (server-side filtering in _send_rpc_to_room)
Protocol change New message type ID (11) None None None Extends existing RPC binary format

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for sending RPCs to specific client number(s) (instead of always broadcasting), by extending the RPC payload with an optional target list and updating server routing accordingly.

Changes:

  • Unity: adds targeted RPC public API overloads that forward to RPCManager.SendTo(...) when targets are provided.
  • Server: updates _send_rpc_to_room to unicast RPCs only to specified target client numbers (broadcast otherwise).
  • Python serializer: extends RPC binary frame to include targetClientNos as count (byte) + ushort[].

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

File Description
STYLY-NetSync-Unity/Packages/com.styly.styly-netsync/Runtime/NetSyncManager.cs Adds new public RPC overloads intended to support targeted delivery.
STYLY-NetSync-Server/src/styly_netsync/server.py Routes RPCs to specific client identities when targetClientNos is present; otherwise broadcasts.
STYLY-NetSync-Server/src/styly_netsync/binary_serializer.py Serializes/deserializes targetClientNos in the RPC wire format.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@from2001 from2001 changed the title feat: add targeted RpcTo delivery by client number feat: add targeted RPC delivery by client number Feb 27, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@hacha
Copy link
Collaborator

hacha commented Feb 28, 2026

LGTM

@from2001 from2001 merged commit 9509abc into develop Feb 28, 2026
@from2001 from2001 deleted the codex/add-rpcto-functionality-for-target-clients-j8m6gg branch February 28, 2026 09:15
@from2001
Copy link
Collaborator Author

Closed #239

@from2001
Copy link
Collaborator Author

rpc_targeted_delivery_en

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants