Using the Auxiliary Stream to Send Large Amounts of Data from an Xbox One Title to a SmartGlass Device

The standard UDP-based SmartGlass communication channel can be insufficient when you need to send large amounts of application-specific data between your Xbox One titles and SmartGlass devices. The standard channel uses a single socket in the SmartGlass service that is in the system operating system to handle communication with all connected SmartGlass devices. The location of this socket requires that application-specific data is marshalled to and from the SmartGlass service, which often requires that the data crosses virtual machine (VM) boundaries between the game operating system and the system operating system. This cross-VM communication is the main bottleneck that limits throughput of application-specific data.

For circumstances that require application-specific communication with high throughput, SmartGlass provides auxiliary data stream that uses a TCP connection between the title and the SmartGlass device that is exclusively dedicated to sending application-specific data.

To use the auxiliary stream for communication, both the title and the SmartGlass device must explicitly open the stream. After both sides open the stream, they can both read and write data to the stream. All data that you send through the auxiliary stream is encrypted and checked for integrity. SmartGlass generates the keys that it uses to secure the data randomly and shares the keys by using the UDP protocol for the SmartGlass service.

To use the auxiliary stream in an Xbox One title

  1. In the code for your Xbox One console title, create methods that you want to run when each of the SmartGlass.SmartGlassAuxiliaryStream::OnConnect, SmartGlassAuxiliaryStream::OnError, SmartGlassAuxiliaryStream::OnReceive, SmartGlassAuxiliaryStream.OnSend events occurs.

    C++

    void Player::OnAuxStreamConnect(SmartGlassAuxiliaryStream^ stream, Object^ obj)
    {
        // Your code goes here.
    }
          
    void Player::OnAuxStreamSend(SmartGlassAuxiliaryStream^ stream, 
        SmartGlassAuxiliaryStreamWriteStats writeStats)
    {
        // Your code goes here.
    }
          
    void Player::OnAuxStreamReceive(SmartGlassAuxiliaryStream^ stream, 
        SmartGlassAuxiliaryStreamReadStats readStats)
    {
        // Your code goes here.
    }
          
    void Player::OnAuxStreamError(SmartGlassAuxiliaryStream^ stream, int error)
    {
        // Your code goes here.
    }  
    
  2. Attach these event handlers to the corresponding events.

    C++

    _device->AuxiliaryStream->OnConnect += 
        ref new TypedEventHandler<SmartGlassAuxiliaryStream^, Object^>(this, 
        &Player::OnAuxStreamConnect);
    _device->AuxiliaryStream->OnError += 
        ref new TypedEventHandler<SmartGlassAuxiliaryStream^, int>(this, 
        &Player::OnAuxStreamError);
    _device->AuxiliaryStream->OnSend += 
        ref new TypedEventHandler<SmartGlassAuxiliaryStream^, 
        SmartGlassAuxiliaryStreamWriteStats>(this, &Player::OnAuxStreamSend);
    _device->AuxiliaryStream->OnReceive += 
        ref new TypedEventHandler<SmartGlassAuxiliaryStream^, 
        SmartGlassAuxiliaryStreamReadStats>(this, &Player::OnAuxStreamReceive);  
    
  3. Call the SmartGlassAuxiliaryStream::Open method to open the stream from the Xbox One console end.

    C++

    _device->AuxiliaryStream->Open();  
    
  4. Call the SmartGlassAuxiliaryStream::Read and SmartGlassAuxiliaryStream::Write methods to get data from and send data to the auxiliary stream.

    C++

    stream->Write(stream->Read(readStats.AvailableBytes, &readStats), 
            &writeStats);  
    
  5. Call the SmartGlassAuxiliaryStream::Close method when you no longer need to use the stream.

    C++

    _device->AuxiliaryStream->Close();  
    
  6. In the package.appxmanifest file for your Xbox One console title, add the socket description entries for the auxiliary stream under the <Extensions> element.
              <Extensions>
                  <mx:Extension Category="windows.xbox.networking">
                      <mx:XboxNetworkingManifest>
                          <mx:SocketDescriptions>
                              <mx:SocketDescription Name="SmartGlassTcp" SecureIpProtocol="Tcp" BoundPort="0">
                                  <mx:AllowedUsages>
                                      <mx:SecureDeviceSocketUsage Type="Initiate" />
                                      <mx:SecureDeviceSocketUsage Type="Accept" />
                                      <mx:SecureDeviceSocketUsage Type="SendDebug" />
                                      <mx:SecureDeviceSocketUsage Type="ReceiveDebug" />
                                      <mx:SecureDeviceSocketUsage Type="SendInsecure" />
                                      <mx:SecureDeviceSocketUsage Type="ReceiveInsecure" />
                                  </mx:AllowedUsages>
                              </mx:SocketDescription>
                          </mx:SocketDescriptions>
                          <mx:SecureDeviceAssociationTemplates>
                              <mx:SecureDeviceAssociationTemplate
                                  Name="SmartGlassTrafficTcp"
                                  InitiatorSocketDescription="SmartGlassTcp"
                                  AcceptorSocketDescription="SmartGlassTcp"
                                  MultiplayerSessionRequirement="None">
                                  <mx:AllowedUsages>
                                      <mx:SecureDeviceAssociationUsage Type="Default" />
                                  </mx:AllowedUsages>
                              </mx:SecureDeviceAssociationTemplate>
                          </mx:SecureDeviceAssociationTemplates>
                      </mx:XboxNetworkingManifest>
                  </mx:Extension>
              </Extensions>  
    
  7. Include similar code to open the auxiliary stream in the device-side app that you create with the SmartGlass Native SDK. For information about how to use the auxiliary stream in an app that you create with the SmartGlass Native SDK, see “Using the Auxiliary Stream to Send Large Amounts of Data Between a SmartGlass Device and an Xbox One Console” in the SmartGlass Native SDK documentation.

See also

SmartGlassAuxiliaryStream::OnConnect

SmartGlassAuxiliaryStream::OnError

SmartGlassAuxiliaryStream::OnReceive

SmartGlassAuxiliaryStream::OnSendt

SmartGlassAuxiliaryStream::Open

SmartGlassAuxiliaryStream::Read

SmartGlassAuxiliaryStream::Write

SmartGlassAuxiliaryStream::Close