19. Appendix: VSocket

19.1. VSocket Overview

Positioned in a layer lower than NetZ, the NEX VSocket is a socket-like library that provides simple packet sending and receiving functionality without performing P2P session management. VSocket can connect to all NEX server services including NAT traversal features, and is appropriate for integrating any existing P2P libraries and NEX. To use the VSocket library, you must link it to the OnlineCore library. There is no need to link the NetZ library.

Sends up to 1300 bytes without guaranteeing arrival. Packet signature and packet encryption features are provided. To perform a signature check, communication with independent servers cannot be performed.

19.2. Notes

Please contact Nintendo if you want to use VSocket, or if samples are required. Note that the following must be implemented for use.

  • Call the StartNatSession function before starting P2P communications, and call the StopNatSession function after terminating P2P communications.
  • Call the StartNatSession and StopNatSession functions each time you terminate matchmaking and the partner changes.
  • To maintain the P2P NAT port, do not allow a non-communication state to continue for more than 10 seconds for all P2P communication destinations. If necessary, send a keep-alive packet to maintain the NAT port.

If you do not follow these steps, Nintendo cannot guarantee that P2P communication can be maintained.

Except for certain P2P communications, the buffer for packets is managed by the packet buffer manager in a fixed-length memory pool. If the packet buffer runs out of space, the send function returns VSocket::PacketBufferFull. If VSocket::PacketBufferFull is thrown, dispatch the data and wait briefly before trying to send the data again, or increase the packet buffer. For more information about the packet buffer, see Managing Packet Buffer Memory in Memory Management.

19.3. Implementation

See the VSocket.cpp file that is provided separately.

The setting of a signature key distributed from the game server is required. In the thread-safe mode, the VSocket class operates in thread-safe mode. The send and Dispatch locks are shared, but for reception, operation is with a different lock, so sending and receiving do not conflict.

19.4. Independent Implementation of the Host Migration Extension

Call the MatchMakingClient::UpdateSessionHost function to update the host registered in the game server when the host that should be joining first during matchmaking is not the host registered on the game server, such as when the host role of the P2P session created by the application gets changed.

19.5. Error Handling

When the VSocket::ProbeStations function shows that NAT traversal has failed, you can get QERROR(Transport, NatTraversalError) with the CallContext::GetOutcome function. In this case, get the network error code, pass it to the error/EULA applet, and then shut down communication.(See the section on asynchronous processing in NEX Library (General), which is included in Cafe-NEX documentation.


CONFIDENTIAL