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.

Dev Panel Widget

To view information related to network connection and network transfers completed by the application the Network Information dev widget can be used. This widget can be found by opening dev panel and selecting "Network Information". For more information on the dev panel and how to open it in an application see CYIDevPanel.

This dev widget displays the following:

When the widget is opened for the first time on each application launch it starts to observe the network transfers completed by CYIHTTPService and display them in the widget. There are also configuration options for the widget which allows the user to start/stop observing transfers, start observing transfers on application startup and clear the transfer information that the widget is holding onto. If the user would like to observe network transfers that occur early on in application startup it is recommended that the configuration to start observing transfers on startup be activated. When the widget is observing network transfers it holds onto the CYIHTTPRequest and CYIHTTPResponse shared objects; preventing them from being destroyed when the application releases their reference. If the user would like to free these objects the clear observed transfers button in the widget configuration can be used to do so. Due to the retention of network responses the application will consume more memory while transfers are being observed, for this reason a warning with the text "REC. NETWORK TRANSFERS" will be dispalted in the bottom right corner of the HUD while observing is active. While responses are It should also be noted that any requests completed by CYIConnectivity to determine connectivity will not be displayed by the widget to avoid polluting the request/response list.

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 the cached item's associated CYIUrl. 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  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  CYIWebSocket
 Implements a basic secure WebSocket. More...
 
class  CYIUrl
 A class used to encapsulate an URL. More...
 
class  CYIUrlQuery
 An URL query builder. 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

◆ operator!=() [1/2]

bool operator!= ( const CYIHTTPHeader lhs,
const CYIHTTPHeader rhs 
)

◆ operator!=() [2/2]

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

◆ operator==() [1/2]

bool operator== ( const CYIHTTPHeader lhs,
const CYIHTTPHeader rhs 
)

◆ operator==() [2/2]

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