3.1. Basic Features of PiaLocal

This section describes how to use the basic features of PiaLocal in applications.

It describes how to use PiaSession sessions. For more information about managing the mesh network manually, see 6.19.3. Directly Controlling Meshes for Local Communications.

Initialization Order

When using PiaLocal, initialize the modules in the following order.

  1. Initialize PiaCommon.
  2. Initialize PiaLocal.
  3. Initialize PiaTransport.
  4. Initialize PiaSession.

For more information about each of these processes, see the appropriate pages of the programming manual.

Finalization Order

When using PiaLocal, finalize the modules in the following order.

  1. Finalize PiaSession.
  2. Finalize PiaTransport.
  3. Finalize PiaLocal.
  4. Finalize PiaCommon.

For more information about each of these processes, see the appropriate pages of the programming manual.

Initialize PiaLocal.

Initialize PiaLocal as follows.

nn::Result result;

// Initialize the local module.
result = nn::pia::local::Initialize();
PIA_ASSERT(result.IsSuccess());
 
// Start setup of the local module.
result = nn::pia::local::BeginSetup();
PIA_ASSERT(result.IsSuccess());
 
// Create an instance of LocalNetwork.
result = nn::pia::local::LocalNetwork::CreateInstance();
PIA_ASSERT(result.IsSuccess());
 
// Prepare settings to pass to Initialize.
nn::pia::local::UdsNetworkSetting setting;
setting.m_ReceiveBufferSize = UDS_RECEIVE_BUFFER_SIZE;
setting.m_ScanBufferSize = UDS_SCAN_BUFFER_SIZE;
setting.m_SendOption = UDS_SEND_OPTION;
setting.m_ReceiveOption = UDS_RECEIVE_OPTION;
setting.m_IsEnableHostMigration = ENABLE_HOST_MIGRATION;
 
// Initialize LocalNetwork.
result = nn::pia::local::LocalNetwork::GetInstance()->Initialize(setting);
PIA_SAMPLE_ASSERT_RESULT_IS_SUCCESS(result);
 
// Create an instance of LocalFacade.
result = nn::pia::local::LocalFacade::CreateInstance();
PIA_ASSERT(result.IsSuccess());
 
// End the setup of the local module.
result = nn::pia::local::EndSetup();
PIA_ASSERT(result.IsSuccess());

 

Joining a Session

Use PiaSession API functions to join a session (a local network and a P2P mesh network). For more information about joining sessions, see 6.4. Basic Features - Browse Matchmaking.

 

Finalizing PiaLocal

When you have finished using PiaLocal, finalize it.

// Destroy the instance of LocalFacade.
nn::pia::local::LocalFacade::DestroyInstance();
 
// Finalize LocalNetwork.
nn::pia::local::LocalNetwork::GetInstance()->Finalize();
 
// Destroy the instance of LocalNetwork.
nn::pia::local::LocalNetwork::DestroyInstance();

// Finalize the local module.
nn::pia::local::Finalize();

 

Nearby Network Search Feature

The nearby network search feature allows you to search for nearby networks while connected to a network.

Normally, you cannot search for nearby networks while already connected to a network due to limitations of the CTR system. This feature allows you to work around these limitations.

The clients (not the host) perform the search, and then the host receives search results from the clients. Search results are only available when two or more devices are connected.

The host notifies each client of the start and finalization of the search.

To enable this feature, set m_IsEnableAroundNetworkSearch to true for the UdsNetworkSetting instance passed when the LocalNetwork::Initialize() function is called.