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::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.

Namespaces

 yi::deprecated
 Deprecated classes.
 

Classes

struct  CYILRUData
 Base class for data to be stored in the cache. Derive from this class to add custom data to the cache. More...
 
struct  CYILRUSortItem
 
class  CYILRUCache
 This class provides a Least Recently Used (LRU) cache implementation. More...
 
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  CYIAbstractDownloadHelper
 
class  CYIAssetDownloadHelper
 A download helper class used for downloading assets off of web servers. 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  CYINetworkUtilities
 
class  CYIOAuthRequest
 This class prepares an OAuth HTTP Request over HTTP. More...
 
class  CYIRemoteAssetDownloadHelper
 A download helper class used for downloading assets off of web servers. 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...
 

Enumerations

enum  HTTP_STATUS_CODE {
  HTTP_NONE = 0,
  HTTP_OK = 200,
  HTTP_REDIRECT_FOUND = 302,
  HTTP_NOT_MODIFIED = 304,
  HTTP_UNAUTHORIZED = 401,
  HTTP_NOT_FOUND = 404,
  HTTP_YOUI_NETWORK_TIMED_OUT = 997,
  HTTP_YOUI_CONNECTION_TIMED_OUT = 998,
  HTTP_UNDEFINED = 999,
  HTTP_YOUI_UNDEFINED = HTTP_UNDEFINED
}
 

Enumeration Type Documentation

Enumerator
HTTP_NONE 
HTTP_OK 
HTTP_REDIRECT_FOUND 
HTTP_NOT_MODIFIED 
HTTP_UNAUTHORIZED 
HTTP_NOT_FOUND 
HTTP_YOUI_NETWORK_TIMED_OUT 
HTTP_YOUI_CONNECTION_TIMED_OUT 
HTTP_UNDEFINED 
HTTP_YOUI_UNDEFINED