6. Items to Check Every Frame

There are several items should be checked every frame when using NEX.

If all of the conditions are satisfied, always use the specified API to implement error handling.

6.1. Game Server Connectivity Check

After logging in to the game server successfully with the NgsFacade::Login function, check for connectivity with the game server every frame using the NgsFacade::IsConnected function.

For more information, see the function reference.

6.2. Fatal NetZ Error Check

While a NetZ instance is present, use NetZ::GetFatalError in every frame to check for fatal errors.

For more information, see the function reference and the error handling section in P2P Communication Features.

6.3. Session Validity Check

After creating and joining a session using Session::CreateSession and Session::JoinSession, use Session::CheckGameIsOver every frame to check whether the session has ended.

If host migration is enabled in HostMigrationCallback::Register, use HostMigrationCallback::SessionHostIsOrphan in every frame to check whether the local station is the host of an orphaned session.

For more information, see the function reference.

7. Recommended Check Topics

7.1. AC Network Connectivity Check

Use the AC library included in CTR-SDK to check network connectivity. NEX is internally constructed so that when an AC disconnect error is returned while transmitting and receiving packets, further send processes and remote method call processes fail. When this happens, the NgsFacade::IsConnected function (BackEndServices::IsConnected) returns false. This check runs during packet communication, and is not immediate.

Warning

We do not recommend calling the nn::ac::CTR::IsConnected function, used to check network connectivity by the AC library, every game frame. Avoid calling it directly every frame. Rather than using the nn::ac::CTR::IsConnected function, monitor events registered using the nn::ac::CTR::RegisterDisconnectEvent function every frame.

When disconnected from the network, quickly shut down the NEX library, because NEX features can no longer be used.

By making the Core::GetInstance function -> SetTerminateImmediately(true); the overall finalization process is faster by not completing the standard disconnect process. (This is an irregular termination when there is a network communication error. Do not use it in a standard finalization sequence. For more information, see the function reference. ) The Core::SetTerminateImmediately function is set to true when the AC disconnect error is found during packet communication.

For API specifications of the AC library and error codes that must be displayed, see the CTR-SDK references and other documentation.

Code 7.1 Sample Code for Checking Network Connectivity Using the AC Library

// Set up an event for receiving disconnect notifications.
nn::os::Event ACDisconnectedEvent;

// Register an event.
ACDisconnectedEvent.Initialize(true);
nn::ac::CTR::RegisterDisconnectEvent(&ACDisconnectedEvent);


// Check the following every frame.
if ( ACDisconnectedEvent.Wait(0) )
{
    // Quickly shut down the NEX library.
}

Note

For local communications, you must check network status update event connectivity instead of checking network connectivity with AC. For more information, see the UDS Communication Feature - Network Status Update Events section in the PIA Local PIA documentation.


CONFIDENTIAL