UDN
Search public documentation:

ReplicationPatternClientToServerRPC
日本語訳
中国翻译
한국어

Interested in the Unreal Engine?
Visit the Unreal Technology site.

Looking for jobs and company info?
Check out the Epic games site.

Questions about support via UDN?
Contact the UDN Staff

UE3 Home > Networking & Replication > Client to server remote procedure call pattern

Client to server remote procedure call pattern


Overview


Client to server remote procedure calls are used when you want to send client data to the server. Client data by itself will not replicate to the server on its own. This ensures that the server maintains control of all the class variables within the game state. By forcing clients to use client to server remote procedure calls, servers always have a chance to intercept all incoming client data.

Player Controller class


Player controllers act as one of the communication bridges between the client and the server. Each player owns their own player controller. Reliable was used here only for demonstration purposes. Reliable should be used when the remote procedure call and its parameters absolutely need to reach the server. Unreliable should be used when the remote procedure call and its parameters don't matter if they get lost or dropped in bandwidth saturated situations.

CTSRPC_PlayerController.uc
class CTSRPC_PlayerController extends PlayerController;

/**
 * Exec function which allows the client to send text to the server
 *
 * Network: Client
 */
exec function SendTextToServer(String TextToSend)
{
  // If the role of the player controller is not authoritive
  // Text is not empty
  if (Role < Role_Authority && TextToSend != "")
  {
    `Log(Self$":: Client wants to send '"$TextToSend$"' to the server.");
    ServerReceiveText(TextToSend);
  }
}

/**
 * Server function which receives text from the client
 *
 * Network: Dedicated/Listen Server
 */
reliable server function ServerReceiveText(String ReceivedText)
{
  // If the role of the player controller is authoritive
  // Text is not empty
  if (Role == Role_Authority && ReceivedText != "")
  {
    `Log(Self$":: Server received text, '"$ReceivedText$"'.");
  }
}

defaultproperties
{
}

Game Info class


The GameInfo only exists on the server. In this pattern, it is only used to spawn the correct PlayerController for connecting players.

CTSRPC_GameInfo.uc
class CTSRPC_GameInfo extends GameInfo;

defaultproperties
{
  PlayerControllerClass=class'CTSRPC_PlayerController'
}

Testing


On the client, SendTextToServer was executed with the parameter "My message to the server. Road house!".

CTSRPC_ClientConsoleWindow.jpg

On the server, the remote procedure call 'ServerReceiveText' was received along with the parameter "My message to the server. Road house!".

CTSRPC_ServerConsoleWindow.jpg

Download


  • Download the source code used in this pattern. (ClientToServerRPCExample.zip)