기술 자료

지원

Relay

Relay

연결 상태 유지

Prevent connection timeouts by regularly sending messages to the Relay server.
읽는 시간 1분최근 업데이트: 한 달 전

Relay 서버는 일정 기간 동안 활동이 없으면 자동으로 클라이언트의 연결을 해제합니다. Relay가 클라이언트의 연결을 해제할 때까지의 기본 TTL(Time to Live)은 10초입니다. 호스트가 혼자 있을 때(
BIND
메시지가 전송되었지만 다른 플레이어가
CONNECT
메시지로 연결하기 전) 연결을 해제하는 TTL은 60초입니다. 발송자든 수신자든 해당 클라이언트와 관련되어 Relay 서버가 수신하는 모든 메시지는 이 시간 초과를 재설정합니다.
메시지 빈도가 낮은 게임의 경우,
Update()
루프와 같이 정기적으로 호출하는 메서드를 사용하여 연결 상태를 유지해야 합니다. Relay를 NGO와 함께 사용하는 경우, 네트워크 관리자(
NetworkManager
)가 자동으로 연결 상태를 유지합니다. 하지만 연결 상태를 유지하려면
StartClient
또는
StartHost
를 성공적으로 호출해야 합니다.
Relay를 UTP와 함께 사용하는 경우, 호스트 플레이어와 참여 플레이어 모두에게
NetworkDriver
업데이트를 정기적으로 예약하면 UTP는 자동으로 연결 상태를 유지합니다. 일반적으로 새 연결을 수락하고 메시지를 수신하려면 업데이트를 정기적으로 예약해야 합니다. 다음 코드 샘플은 연결 상태를 유지하는 방법을 보여 줍니다.
//Call the below regularly, e.g., in Monobehaviour.Update()void Example_KeepingConnectionAlive(){ // Update the NetworkDrivers regularly to ensure the host/player is kept online. if (HostDriver.IsCreated && isRelayServerConnected) { HostDriver.ScheduleUpdate().Complete(); //Accept incoming client connections while (HostDriver.Accept() != default(NetworkConnection)) { Debug.Log("Accepted an incoming connection."); } } if (PlayerDriver.IsCreated && clientConnection.IsCreated) { PlayerDriver.ScheduleUpdate().Complete(); //Resolve event queue NetworkEvent.Type eventType; while ((eventType = clientConnection.PopEvent(PlayerDriver, out _)) != NetworkEvent.Type.Empty) { if (eventType == NetworkEvent.Type.Connect) { Debug.Log("Client connected to the server"); } else if (eventType == NetworkEvent.Type.Disconnect) { Debug.Log("Client got disconnected from server"); clientConnection = default(NetworkConnection); } } }}