- Home /
RPC to server from client
Im trying to send the player's username and password from the client to the server (then to the database which i have done successfully). On the client game controller I have this when the player attempts to log in:
GetComponent<NetworkView>().RPC("AuthLogin", RPCMode.Server, username, password);
//network.RPC() <- seems to obsolete, but oh well.
and then on my server controller I have this:
[RPC]
void AuthLogin(string user, string pass) {
Debug.Log(user + ":" + pass);
}
It seems that its trying to look for the RPC function in the client's controller.. How do I make it send it to the server?
Here is the error:
RPC call failed because the function 'AuthLogin' does not exist in the any script attached to'C_controller'
can you show the code where you're connecting to server ?
Im just connecting with the standard`Network.Connect(...);`
Answer by NathanHold · Aug 14, 2015 at 12:41 PM
RPC does a Remote Procedure Call on the GameObject your script is currently on.
For this you should have a single NetworkController GameObject which either the Client or Server controller scripts are on or a complete NetworkController script that handles both client and server code. You could also have both GameObjects and scripts exist on client and server and get the NetworkView of the server GameObject and RPC call on that.
If you don't want to do any of that you'll have to create your own RPC library.
thanks for a solution. my reason being is because i have a database and i dont want the client to directly access the database. I want the client to call an RPC in the server and the server can handle the database request..
@thornekey: It's enough if the client script has an RPC method with the same signature (name and parameters). The method can be empty but it has to be there ^^. I've once done the same thing and seperated the client and server logic into seperate scripts. At the bottom of each script i had a block of empty RPC definitions for the other side just to make them work.
$$anonymous$$eep in $$anonymous$$d that you're using Unity's old Network system (RakNet). Unity now has a new networking system (UNet) which is more powerful but also slightly more complicated.
Your answer
Follow this Question
Related Questions
RPC not being called 1 Answer
Network how to send data/activate function 1 Answer
How can I send a mouse click to a server using an RPC? 0 Answers
Generic RPC Call 1 Answer
Multiple Cars not working 1 Answer