UDN
Search public documentation:

ReplicationPatternServerToClientRPCKR
English Translation
日本語訳
中国翻译

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 홈 > 네트워킹과 리플리케이션 > 서버 투 클라이언트 리모트 프로시저 콜 패턴

서버 투 클라이언트 리모트 프로시저 콜 패턴


문서 변경내역: James Tan 작성. 홍성진 번역.

개요


서버 투 클라이언트 리모트 프로시저 콜 패턴은 클라이언트 측에서 어떤 로직을 돌리고자 할 때 사용됩니다. 데이터를 클라이언트에 푸시만 하려는 경우, RepNotify 패턴같은 변수 리플리케이션 패턴을 사용하면 됩니다. 들어오는 데이터를 사용하여 클라이언트에 로직을 조금 돌리려 할 때도 이걸 사용하면 됩니다. 예제라면 서버가 연결된 클라이언트 모두에게 메시지를 방송하고자 할 때입니다.

Player Controller 클래스


PlayerController 는 클라이언트와 서버간 통신의 다리 역할을 합니다. 이 경우 서버는 ReceiveBroadcast 함수와 그 파라미터를 클라이언트에 리플리케이트할 수 있습니다.

STCRPC_PlayerController.uc
class STCRPC_PlayerController extends PlayerController;

/**
 * 서버에서의 방송을 수신하는 client 함수
 *
 * 네트워크: 클라이언트
 */
reliable client function ReceiveBroadcast(String ReceivedText)
{
  `Log(Self$":: Server sent me '"$ReceivedText$"'.");
}

defaultproperties
{
}

Game Info 클래스


GameInfo 클래스는 서버에만 있습니다. 이 패턴에서는 SetTimer 함수를 사용하여 RandomBroadcast 를 매 초마다 한 번씩 실행합니다. RandomBroadcast 는 서버상의 WorldInfo 에 저장된 모든 PlayerController 인스턴스에 걸쳐 반복 처리한 다음 ReceiveBroadcast 함수와 그 파라미터를 PlayerController 클라이언트 버전으로 리플리케이트합니다.

STCRPC_GameInfo.uc
class STCRPC_GameInfo extends GameInfo;

/**
 * GameInfo 가 생성된 이후 Post Begin Play 실행
 *
 * 네트워크: 데디케이티드/리슨 서버
 */
function PostBeginPlay()
{
  Super.PostBeginPlay();

  // 랜덤 메시지를 모든 플레이어에게 방송하는 타이머 설정
  SetTimer(1.f, true, 'RandomBroadcast');
}

/**
 * 랜덤 메시지를 모든 플레이어에게 방송
 *
 * 네트워크: 데디케이티드/리슨 서버
 */
function RandomBroadcast()
{
  local STCRPC_PlayerController PlayerController;
  local int i;
  local string BroadcastMessage;

  if (WorldInfo != None)
  {
    // 랜덤 텍스트 메시지 구성
    for (i = 0; i < 32; ++i)
    {
      BroadcastMessage $= Chr(Rand(255));
    }

    ForEach WorldInfo.AllControllers(class'STCRPC_PlayerController', PlayerController)
    {
      `Log(Self$":: Sending "$PlayerController$" a broadcast message which is '"$BroadcastMessage$"'.");
      PlayerController.ReceiveBroadcast(BroadcastMessage);
    }
  }
}

defaultproperties
{
  PlayerControllerClass=class'STCRPC_PlayerController'
}

테스팅


클라이언트에서 1 초 정도마다 ReceiveBroadcast 와 아주 랜덤한 방송 메시지가 수신됩니다. STCRPC_ClientConsoleWindow.jpg

서버에서 1 초 정도마다 RandomBroadcast 가 호출되며, 서버에 연결된 모든 PlayerController 에서 ReceiveBroadcast 를 실행합니다. STCRPC_ServerConsoleWindow.jpg

내려받기