**************** ServerConnection **************** The core of the plugin is the **ServerConnection** component. This component handles all aspects of connection and communication with the PlayReal **Scalable Server** You can only use the **ServerConnection** component or you can build your game upon the game architecture proposed in the sample. Access to the documentation of **Scalable Server**: http://ssdoc.asmodee.net .. image:: ../Images/ServerConnection_diagramme.JPG Integration =========== Create an object in the hierarchy containing the **PlayReal Manager** script. This is the script that hosts the unique instance of **ServerConnection**. We wish that this component is unique throughout the lifetime of the game. It is then necessary to ensure that the object containing the **PlayReal Manager** script is never destroyed during the scene change 1. Create the object which we call Manager .. image:: ../Images/Hierarchy_create_manager.png Renaming the object to **Manager** .. image:: ../Images/Hierarchy_rename_manager.png 2. Add **PlayReal Manager** component to the Manager object .. image:: ../Images/Inspector_add_network_manager.png 3. Select the setting by clicking the circle to the right of the parameter **Network Parameters** .. image:: ../Images/Inspector_set_network_parameter.png In the **Assets** tab, select the desired parameter .. image:: ../Images/Selector_select_network_parameter.png 4. Add the component **Singleton** in the Manager object .. image:: ../Images/Inspector_add_singleton.png **Singleton** component visible under the **PlayReal Manager** : .. image:: ../Images/Inspector_singleton.png Use === Communication with the **Scalable Server** is done asynchronously. A request is sent to the server and the component waits for a response. When it receives the response, it raises an event. Connection and authentication of a user : 1. Subscribe to the events ``ConnectedToServerEvent.AsyncConnectedEvent`` :: NetworkManager.Instance.ServerConnection.ConnectedToServerEvent += ServerConnection_ConnectedToServerEvent; NetworkManager.Instance.ServerConnection.AsyncConnectedEvent += ServerConnection_AsyncConnectedEvent; 2. Creation of methods called when events are fired :: private void ServerConnection_ConnectedToServerEvent() { NetworkManager.Instance.ServerConnection.AuthenticateUser("login", "password"); } private void ServerConnection_AsyncConnectedEvent(AsyncConnectedRequest asyncConnectedRequest) { Debug.Log(string.Format("User {0} is authenticated", asyncConnectedRequest.player.name)); } 3. Deleting events :: private void Dispose() { NetworkManager.Instance.ServerConnection.ConnectedToServerEvent -= ServerConnection_ConnectedToServerEvent; NetworkManager.Instance.ServerConnection.AsyncConnectedEvent -= ServerConnection_AsyncConnectedEvent; }