Question about RPC logic...

Hello everyone, please excuse my noob question as I’m learning Unity and I’ve got to the point of Network. As I was reading over M2H’s Networking tutorial (Zero to Hero) the part about RPC is very interesting. The way I understand it all the players network traffic communicate using the ‘networkView’ as a sort of tunnel to each other; like being linked together.

I figured like everything else I could call a RPC method defined in the Server from the Client. However, the only way I’ve been able to get the communication to work properly is to include the RPC method in the client code as well, even if RPCMode is set to ‘Server’. this is much no good. I’m wanting to have a ‘Server’ processes running on, lets say ‘Server Machine 1’ and have multiple clients connect to it, server is authorative and (the most important part) the clients have 0 access to the code being executed server side.

Info:
Two separate projects: Client and Server

Components of Main Camera of both:
networkView (off,mainCamera)
script (either server OR client)

Client (attempting to call method on the server):

networkView.RPC("Poke", RPCMode.Server);

Server

var PokeVar	:	boolean		=	false;
...
@RPC
function Poke(){
	PokeVar = true;
}

Am I doing something wrong here or do I not understand RPC? Does the method -have- to be defined in the client?

Much thanks for the help, I’m face-desking here.

Pheagey

P.S.: when I -do- define it on both sides it does work. But again, I do not wish the clients to ever in any way, have access to the server side code.

Not sure for a 100% but i think the function needs to exist on all instances that call or receive it.
Maybe check the docs, must be in there somewhere.

The method must be declared with @RPC annotation in both the caller and receiver (client/server). What’s happening behind the scenes is that @RPC is really a network call and in order to know what method and how to translate the request on both ends the method must be defined on each end.

Btw, you only really need to declare it on both ends, if your client code does nothing with the method call then you can leave it empty:

@RPC
function Poke( )
{
// client stub, do nothing
}

O, awesome. So I just need to define the method but the logi for the server can stay, well, on the server…THAT will work nicely; Thank you very much!

I did a test, the result seemed to speak: for network traffic efficiency, unity will encode RPC function name in compiling time, and just uses the encoded name (may be an id) for network. So both sides (server and client) must have the RPC function name at compiling time.

For seperating server code and client code, i think Lypheus’ solution is the right way.