CTR Pia
4.11.3
Game Communication Engine
|
This sample demonstrates the use of the nn::pia::transport
module's ReliableProtocol
and UnreliableProtocol
classes.
This sample demonstrates the following.
nn::pia::transport::UnreliableProtocol
nn::pia::transport::ReliableProtocol
nn::pia::transport::Transport
nn::pia::transport::ThreadStreamManager
nn::pia::transport::TransportAnalyzer
Select the communication mode from this screen. Once selected, matchmaking occurs, then you transition to the Main screen.
Input | Operation |
---|---|
A Button | Run local communication (UDS library) as a host. After you successfully create a session, you transition to the Main screen. |
B Button | Run local communication (UDS) as a client. Search the UDS network and join what you find, and then transition to the Main screen. If you press START during a search of the UDS network, you cancel the search and return to the Mode Selection screen. |
X Button | Run in the mode that uses Internet communication. Perform random matchmaking. If there is a session that can be joined, join it as a client. If there are no sessions, create one as the host. Then you transition to the Main screen. |
START | Exits the program. |
Three protocols are available for sending data to the other stations in the session. While on the Main screen, other devices can join or leave the session at any time. When a session cannot continue because of an error or another reason, you are automatically returned to the Mode Selection screen.
Information about the stations that have joined the session is aligned vertically on the screen. The ID column indicates the station ID. An asterisk (*) to the left of the ID indicates that the corresponding station is the session host. (In this sample, the host is always number 0.) The device shown using the dimmed string "me" is the local device. There is no further information about the local device. When "disconnect" is dimmed, it indicates the station that corresponds to that station ID no longer exists in the session. The row at the very bottom, with the ID of All, indicates information for sending to all stations in the session.
The three protocols, Unreliable, Reliable, and ReliableLarge, are indicated in a row across the top. (An overview of each protocol follows.) Two numbers are displayed for each of the three protocols on each connected station. The upper number indicates the number of sends for that connected station. The lower number indicates the number of receives for that connected station. On the row with the ID of All, only the number of sends is displayed because only sends can be performed.
The "RTT" example on the far right shows the Round Trip Time (RTT) for that station and the number of RTT sampling values used to calculate that RTT.
The total number of packets successfully sent and received by the local station, in addition to the total data size, are displayed at the bottom of the screen.
Input | Operation |
---|---|
+Control Pad | Moves the cursor to the front of the row, and turns it pink. |
A Button | Performs one send for the station and protocol on which the cursor is aligned. When the send succeeds, the number of sends increases by one. |
X Button | Enables or disables the feature to send once per frame, for the station and protocol on which the cursor is aligned. When this feature is enabled, an at sign (@) displays to the right of the number of sends. Every time a send succeeds, the number of sends increases by one. |
Y Button | Enables or disables the console output during send and receive. There is no output for release builds, regardless of this setting. |
START | Leaves the session and returns to the Mode Selection screen. When the station is a session host, the session ends and all the other devices that were in the session also return to the Mode Selection screen. |
In this sample demo, the following three protocols (communication formats) are made to work in parallel. With Pia, you can combine and use various protocols according to the characteristics of the data that you want to send and the required specifications.
Send data using the UnreliableProtocol
class. When sending to individual stations, you can send approximately 40 bytes of data. When sending to all stations, you can send the maximum amount of data that can be sent by using the UnreliableProtocol
class. (This value is obtained from the UnreliableProtocol::GetDataSizeLimit
function.) Because the arrival of data is not guaranteed with UnreliableProtocol
, the number of receives can be less than the number of sends when packet loss occurs.
Send data using the ReliableProtocol
class. Sends roughly 30 bytes of data per send. Because the arrival of data is guaranteed with ReliableProtocol
, the number of receives matches the number of sends, even if packet loss occurs. However, it may take some time for the numbers of sends and receives to match, because packet loss and other conditions tend to increase sending latency.
As with the Reliable communication protocol, send data using the ReliableProtocol
class. Sends a random amount of data up to a maximum of 1 MB per send. In practical terms, there is a 50 percent chance that 1 MB of data is sent and a 50 percent chance that random-sized data in sizes ranging from 4 bytes to 1 MB is sent. A larger buffer is required to send and receive large data. When sending large data, it takes time for the sent data to arrive, even when no packet loss has occurred. Because the send buffer is occupied during that interval, attempts to send every frame do not succeed, and the number of sends takes a long time to increase. This result is normal.
Reliable
and ReliableLarge
can share the same ReliableProtocol
instance by using separate ports. This enables you to differentiate the data in advance upon receipt, which is convenient when differentiating data for subsequent processes, and for when there are large differences in the size of the data, as in this sample demo. However, note that dividing the protocols (due to sharing the same ReliableProtocol
instance) results in having to allocate the necessary memory for each protocol.
This sample is designed to allow the sending and receiving of a large number of data items at one time when sends-per-every-frame is enabled, but the actual amount of data that can be sent and received is not that large. As a result, there is a restriction on the amount of data that can be sent and received when sending and receiving large amounts of data at the same time.
This sample enables a transport analysis feature using TransportAnalyzer
and periodically outputs analysis data to the log while on the main menu. The analysis data contains a breakdown of the Pia packets along with the number of packets, packet loss, RTT, and other information. Load this log file into tools/TransportAnalyzer/PiaTransportAnalyzer.xlsm
to produce a graph that shows changes in communication status over time.