6.13. Advanced Features - Adjusting Session Behavior

The behavior of a session can be adjusted according to the application.

Changing Behavior Settings

You can change the values of settings related to session processing behavior, such as the maximum allowed quiet time. To change the value of a setting, specify the value you want to set in the corresponding member of the StartupSetting structure that is passed to Session::Startup. You can change the following settings.

  • Communication encryption setting
    Specifies the encryption to use on communication between stations.
  • Maximum allowed quiet time
    Specifies the allowed time period without any communication from other stations (including transmissions from the system and the application). If the period without communication exceeds the setting, that station is treated as disconnected. In full-mesh network topologies, the quiet time check of PiaSession can detect not only host-client disconnections but also client-client disconnections.
  • Keep-alive send interval
    Specifies the interval for sending keep-alives (data that the system sends for stations that are not sending system or application data, so that they are not determined to be quiet). When the time since the last send exceeds the specified time, a keep-alive is sent. The last send time is checked for all other stations and the keep-alive is sent to all other stations.

When changing values on the application side, ensure that the settings between each station do not differ.

When calling Session::Startup without changing any of the StartupSetting values, the default values are used for each setting. The default settings are as follows.

  • Communication encryption setting: Do not encrypt
  • Maximum quiet time: 10 seconds
  • Keep-alive send interval: 1 second
Reference:

The maximum quiet time and keep-alive send interval settings may have a direct effect on packet-loss tolerance, depending on the specifications of the application.

For example, if the default settings are 10 seconds for maximum quiet time and one second for the keep-alive send interval, and the application does not send anything for a set period of time and the packets are lost for 10 consecutive keep-alives with that station, the station is determined to be disconnected.

However, if the application is designed to communicate with stations at shorter intervals than the keep-alive send interval, the system does not send keep-alive packets.

 

Code 6-33. Changing Session Processing Behavior Settings
// Configured at session startup.
 
// Example change in settings.
const u32 APP_MAX_SILENCE_TIME = 15000; //Maximum time without communication: 15000 (milliseconds)
const u32 APP_KEEP_ALIVE_SENDING_INTERVAL = 3000; // Keep-alive interval: 3000 (milliseconds)

// The setting for the name associated with the local station (the name shown in the game screen).
nn::pia::transport::Station::PlayerName playerName;

// Set a name of up to 16 characters, together with the language code.
// In the sample demo, the name of the Mii character is set as an example.
GetLocalPlayerName(&playerName);
 
// Startup setting.
nn::pia::session::Session::StartupSetting startupSetting;
startupSetting.bUsingHostMigration = true; // Host migration setting.
startupSetting.pPlayerName = &playerName; // Player name to use for communication.
startupSetting.maxSilenceTime = APP_MAX_SILENCE_TIME; // Maximum time without communication.
startupSetting.keepAliveSendingInterval = APP_KEEP_ALIVE_SENDING_INTERVAL; // Interval for sending the keep-alive signal.
 
// Startup.
result = nn::pia::session::Session::GetInstance()->Startup(startupSetting);
if (result.IsFailure())
{
    // Error processing.
}
 
/* Go to process to build or join a session. */