Menu
Amazon AppStream
Developer Guide

This documentation is for an older version of Amazon AppStream. For information about the latest version, see the Amazon AppStream 2.0 Developer Guide.

Initializing a Streaming Application

Before your application can start streaming content to a client, it must create the objects that it will use to connect to client sessions and stream content as well as register callback functions to receive event notifications about sessions and clients. The following explanation covers steps 1–5 of Lifecycle of a Streaming Application.

First, your application should create an XStxServerLibrary object. This is the top level object that you use to interact with the libraries you'll use to connect to sessions and stream content to clients.

The following excerpt from the sample streaming application illustrates this step. The excerpt is from the initializeAppStream function of the file main.cpp. The file is in the <SDK_dir>\example_src\server\windows\SimpleDirectXServer directory.

Copy
int runAsAppStreamGame(int argc, const char* argv[]) { // Main AppStream initialization XStxResult result; ... // Create our Server Library handle if ((result = XStxServerLibraryCreate( XSTX_SERVER_API_VERSION_MAJOR, XSTX_SERVER_API_VERSION_MINOR, &g_serverLibraryHandle)) != XSTX_RESULT_OK) return result; ... }

Next, your application creates an XStxServerManager object. To do so, you'll pass in the handle to the XStxServerLibrary object you created previously. Your application uses the XStxServerManager object to receive session assignments from Amazon AppStream.

The following excerpt from the sample streaming application illustrates this step. The excerpt is from the initializeAppStream function of the file main.cpp. The file is in the <SDK_dir>\example_src\server\windows\SimpleDirectXServer directory.

Copy
static XStxResult initializeAppStream() { // Main AppStream initialization XStxResult result; ... // Create our Server Manager if ((result = XStxServerLibraryCreateXStxServerManager( g_serverLibraryHandle, &g_serverManagerHandle)) != XSTX_RESULT_OK) return result; ... }

After the XStxServerManager object is created, your application calls XStxServerManagerSetListener to register an event sink.

The following excerpt from the sample streaming application illustrates this step. The excerpt is from the initializeAppStream function of the file main.cpp. The file is in the <SDK_dir>\example_src\server\windows\SimpleDirectXServer directory.

The code that implements the XStxIServerManagerListener interface and handles the events sent by the XStxServerManager object is located in the file ServerManagerListener.cpp. The file is in the <SDK_dir>\example_src\server\common directory.

Copy
int runAsAppStreamGame(int argc, const char* argv[]) { ... // Set up callbacks so we know when a server is initialized or terminated ZeroMemory(&g_serverManagerListener, sizeof(XStxIServerManagerListener)); g_serverManagerListener.mSize = sizeof(XStxIServerManagerListener); g_serverManagerListener.mServerInitializeFcn = serverInitialize; g_serverManagerListener.mServerSaveStateFcn = serverSaveState; g_serverManagerListener.mServerTerminateFcn = serverTerminate; // Supply our callbacks to AppStream if ((result = XStxServerManagerSetListener( g_serverManagerHandle, &g_serverManagerListener)) != XSTX_RESULT_OK) return result; ... }

After you've registered the event sink, your application is ready to start the server manager to notify Amazon AppStream that it's ready to receive client sessions. To do so, call the XStxServerManagerStart function.

The following excerpt from the sample streaming application illustrates this step. The excerpt is from the initializeAppStream function of the file main.cpp. The file is in the <SDK_dir>\example_src\server\windows\SimpleDirectXServer directory.

Copy
static XStxResult initializeAppStream() { ... // Tell the server to start up if ((result = XStxServerManagerStart( g_serverManagerHandle)) != XSTX_RESULT_OK) return result; ... }

At this point, your application's main function should wait until the XStxServerManager terminates the session. This is done by calling XStxServerManagerWait.

The following excerpt from the sample streaming application illustrates this step. The excerpt is from the runAsAppStreamGame function of the file XStxExampleServer.cpp. The file is in the <SDK_dir>\example_src\server\common directory.

Copy
int runAsAppStreamGame(int argc, const char* argv[]) { ... /** Wait for the session manager to exit */ XStxResult result = XStxServerManagerWait(serverManagerHandle); ... }

While your application is waiting for the session to end, your XStxIServerManagerListener event sink is receiving session events. When the XStxIServerManagerListenerFcnServerInitialize event fires, it indicates that Amazon AppStream has assigned your application a client. For more information, see Initializing a Client Session