持続的接続
Prevent connection timeouts by regularly sending messages to the Relay server.
読み終わるまでの所要時間 1 分最終更新 1ヶ月前
Relay サーバーは、一定時間アクティビティがないクライアントを自動的に 切断 します。Relay がクライアントを切断するまでのデフォルトの生存時間 (TTL、time to live) は、10 秒 です。ホスト単独の場合の切断までの TTL は、60 秒 (
BINDCONNECTUpdate()NetworkManagerStartClientStartHostNetworkDriver//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); } } }}