- Home /
RPC calls to a specific client?
Now I understand for the most part how RPC's work. The only issue i'm having is singling out a specific client. I think this code does that:
networkView.RPC("someFunction", Network.connections[i]);
@RPC function someFunction() { }
But I'm not sure how exactly to get the id for a specific client. How do I find the right connection?
TBC you must look at the SECOND, BOTTO$$anonymous$$ function on the RPC manual page.
that's the key.
(the first version of the function, mentioned at the top, is of little practical use in typical networking coding.)
Answer by Statement · Dec 08, 2010 at 10:41 PM
But I'm not sure how exactly to get the id for a specific client. How do I find the right connection?
What do you mean by "right connection"? If you want to send the RPC to a client with a specific IP (C#):
foreach (NetworkPlayer player in Network.connections)
{
if (player.ipAddress == matchingIp)
{
networkView.RPC("someFunction", player);
}
}
You can probably figure out how to replace the comparison test with something more specific for your problem.
For your updated comment I think you need to do something similar like this in your code:
[RPC]
void OnLogin ( string username, string password, NetworkMessageInfo info )
{
if ( Authenticate( username, password ) )
{
networkView.RPC( "OnLoginSuccess", info.sender );
}
else
{
networkView.RPC( "OnLoginFailure", info.sender );
}
}
does the RPC function send it directly to the client by IP? I thought that you had to use a specific connection that was identified by Unity. I'm trying to send a flag back to the client. The client sends a log in and password. Thats working fine. I just need the server to send back the flag whether or not the password is taken. I could be wrong, but I don't think that your code will do that specifically. I don't know how to find the connection that the client is identified as.
See http://unity3d.com/support/documentation/Components/net-RPCDetails.html, you'll see that you can get a Network$$anonymous$$essageInfo containing the sender (player) of a call. In your OnLogin RPC, you can obtain the sender that way, and respond to only that sender.
That second function is exaclty what I was looking for. Thanks so much :D
Your answer
Follow this Question
Related Questions
Network RPC - exclude specific client 1 Answer
RPC Call Mix Up Issues 0 Answers
Get RPC senders ID, or IP? 1 Answer
client to client ping - NAT punchthrough 1 Answer
Network Instaniate,Lag,Bullet Prefab 1 Answer