You.i Engine
Network

Detailed Description

Networking system.

Network

Intro

You.i Engine provides a networking solution that allows applications to communicate with an external server on every supported platform. This flexible system gives applications the possibility to create dynamically generated layouts by downloading assets, retrieving data and much more.

Sending Requests

The CYIHTTPRequest class sends requests to an external server. Supported by every platform, this class offers all the basic network capabilities:

Example

The following code snippet demonstrates how to properly send a POST request to the CYIHTTPService.

//Start the HTTP Service. This is required to send requests.
//Using CYINetworkConfiguration's default values:
// Response Cache : 7MB
// Persistent Cache : 50MB
CYIHTTPService::GetInstance()->Start(CYINetworkConfiguration());

CYIUrl url(REQUEST_URL);

std::shared_ptr<CYIHTTPRequest> pRequest(new CYIHTTPRequest());

//Set the URL and the Method in the request.
pRequest->SetMethod(CYIHTTPRequest::Method::POST);
pRequest->SetURL(url);

//Create your post data using the CYIURLQuery class.
CYIUrlQuery query;
query.Add("parameterKey", "parameterValue");
pRequest->SetPostData(query.ToString());

//Connect the signals needed to
pRequest->NotifyResponse.Connect(*this, &RequestScreen::OnHTTPResponse);
pRequest->NotifyError.Connect(*this, &RequestScreen::OnHTTPError);

    // To be processed, provide the request to the service.
    std::shared_ptr<CYIHTTPResponse> pResponse;
pResponse = CYIHTTPService::GetInstance()->EnqueueRequest(pRequest);

Receiving Responses

CYIHTTPResponse is the class responsible for receiving the data requested by CYIHTTPRequest. It contains useful information such as the body, the status code, the headers and much more. An instance of CYIHTTPResponse will be received when NotifyResponse is called or it will be returned by EnqueueRequest() if the request was cached.

When receiving the response, it needs to be prepared for general use by calling:

pResponse->Process(pRequest);

Response Caching

In order to keep the runtime performance as optimal as possible, You.i Engine uses a caching system that will keep the CYIHTTPResponses in memory. This is especially useful for generic requests that will be called often. The caching system uses an LRU (Least Recently Used) algorithm. So once the maximum size is reached, the caching system will discard the least recently used items first. The amount of data the system can store is defined per application in CYINetworkConfiguration when instantiating the CYIHTTPService.

Internet Connectivity

The network system provides a functionality to detect the connectivity status on every supported platform. It checks the connectivity at three different levels :

They can be configured to be run periodically or just once giving the flexibility to applications to handle a loss of connectivity gracefully.

Example

This code snippet demonstrate how to properly set the connectivity check.

//Start the HTTP Service. This is required to perform connectivity tests.
CYIHTTPService::GetInstance()->Start(CYINetworkConfiguration());

//Instantiate the network information bridge.
CYINetworkBridgeLocator *pBridge = CYINetworkBridgeLocator::GetNetworkInformationBridge();

//Connect the network information bridge signals required by the application.
pBridge->NetworkStateChanged.Connect(*this, &NetworkInformationScreen::OnNetworkStateChanged);

pBridge->GetConnectivity().StateChanged.Connect(*this, &NetworkInformationScreen::OnConnectivityChanged);

pBridge->GetConnectivity().ProbeCompleted.Connect(*this, &NetworkInformationBridgeTesterApp::OnProbeReceived);

//Checks the connectivity periodically.
//Every 5 seconds by default.
pBridge->GetConnectivity().StartPeriodicChecker();

    //Checks the connectivity once.
pBridge->GetConnectivity().ProbeState();

Limitations

File URI scheme

Is a URI scheme defined in RFC 8089, typically used to retrieve files from within one's own computer. Some platforms currently don't support it and will result in an error.

Use the I/O libraries provided by these platforms to get around that limitation.

Classes

class  CYIDeepLinkBridge
 Class for accessing deep link urls which launched the app, and for launching other apps using urls. More...
 
class  CYIDeepLinkBridgeLocator
 Instantiates the CYIDeepLinkBridge; the instance will be deleted automatically when the application is terminated. More...
 
class  CYIAssetDownloadHelper
 A download helper class used for downloading assets off of web servers or locally when a local path URI is given. More...
 
class  CYICacheContents
 A class representing the contents of what is currently cached within the engine identified by their primary key (the uri) More...
 
class  CYIDownloadHelper
 
class  CYIHTTPHeader
 A class respresenting an HTTP Header Field with a field-name and field-value as specified in https://httpwg.org/specs/rfc7230.html#header.fields. More...
 
class  CYIHTTPRequest
 Contains information required to configure and perform a HTTP request. More...
 
class  CYIHTTPResponse
 An HTTP response class which includes the header and body portions of the response. More...
 
class  CYIHTTPService
 
class  CYINetworkConfiguration
 CYINetworkConfiguration is a data structure that describes the properties of the You.i Engine network components. More...
 
class  CYINetworkConfigurationPS4
 CYINetworkConfigurationPS4 is a data structure that describes the properties of the You.i Engine network components on PlayStation 4. More...
 
class  CYINetworkLogFiltering
 This class provides an interface for logging network calls with customized settings. More...
 
class  IYINetworkService
 The base interface class for HTTP Service CYIHTTPService. More...
 
class  CYINetworkUtilities
 
class  CYIOAuthRequest
 This class prepares an OAuth HTTP Request over HTTP. More...
 
class  CYIServer
 This class contains various data used when authenticating with a server. More...
 
class  IYISocket
 The IYISocket defines the interface to be implemented by any class fulfilling sockets services. More...
 
class  CYISSLRootCertificateProvider
 Provides SSL root certificate information. More...
 
class  CYITCPSecureSocket
 Implements a secure (SSL/TLS) TCP socket. More...
 
class  CYITCPSocket
 Implements a basic TCP socket. More...
 
class  CYIUrl
 A class used to encapsulate an URL. More...
 
class  CYIUrlQuery
 An URL query builder. More...
 
class  CYIWebSocket
 Implements a basic secure WebSocket. More...
 

Functions

bool operator== (const CYIHTTPHeader &lhs, const CYIHTTPHeader &rhs)
 
bool operator!= (const CYIHTTPHeader &lhs, const CYIHTTPHeader &rhs)
 
bool operator== (const CYIHTTPHeader::CacheDirectives &lhs, const CYIHTTPHeader::CacheDirectives &rhs)
 
bool operator!= (const CYIHTTPHeader::CacheDirectives &lhs, const CYIHTTPHeader::CacheDirectives &rhs)
 

Function Documentation

bool operator!= ( const CYIHTTPHeader lhs,
const CYIHTTPHeader rhs 
)
inline
bool operator!= ( const CYIHTTPHeader::CacheDirectives lhs,
const CYIHTTPHeader::CacheDirectives rhs 
)
inline
bool operator== ( const CYIHTTPHeader lhs,
const CYIHTTPHeader rhs 
)
inline
bool operator== ( const CYIHTTPHeader::CacheDirectives lhs,
const CYIHTTPHeader::CacheDirectives rhs 
)
inline