I am in the process of desinging the following in networking in Unity.
I need to have a stateless Server in which connect 2 or more clients. Each client should call via RPC a method in the Server, and the server via RPC should call this method on other clients expect the requestor. (something like broadcast…)
So on each client should I use:
RPCMode.Server //Sends to the server only
but in Server how I will communicate only with the rest of clients ?
RPCMode.Other ???
[RPC]
public void Test(NetworkMessageInfo info) //info stands for the player who send message
{
foreach (NetworkPlayer player in Network.connections) //Network.connections → all connected players.
{
if (player != info.sender)//if a player in all connected players is not equal to message sender,send him a message via rpc
{
//send RPC
}
}
}
That will work and also you can iteratively call each player specificly in server with class Network.connections. check this link in scripting refference
If you need to process / vaildate / change the sent data by the server, you have to use the method @ebyaz explained.
If you just want to use the server as proxy, just use RPCMode.others on the client. This will send the RPC to the server and the server will distribute it automatically to all other clients except the sender.