exchange of data between servers

Options
vetnabivao
edited March 2013 in Photon Server
I have a problem: how to exchange messages between two Photon Server?
I have a game that consists of two parts: the menu and the game room, menu controls one server, the other rooms, both servers Photon, to do so would be possible from a single server to send data to another, and vice versa

Comments

  • chvetsov
    Options
    Hi, vetnabivao.

    First of all you need to establish connection between servers. You can do this with help of ApplicationBase::ConnectToServerTcp(Udp). You will get Peer for this connection and will able to use it how you need
  • can be an example?
  • We are using Server-To-Server connections in our LoadBalancing project (the Master + GameServer applications communicate with each other). As a starting point, have a look at the documentation to understand the concept: http://doc.exitgames.com/photon-server/LoadBalancing/
    You can also have a look at the source code to see an example:
    The "LoadBalancing.GameServer.OutgoingMasterServerPeer" and the "LoadBalancing.MasterServer.GameServer.IncomingGameServerPeer" are a good starting point, - that's the place where we handle communication between Master and Game Servers.

    If you have more detailed questions, please let us know.
  • yes it is probably what I need, it is a pity I did not know English very well, it would be in Russian it would be much better, but will have to deal
  • chvetsov
    Options
    You can send me private messages here, if something will be dificult to understand in English
  • Nicole wrote:
    We are using Server-To-Server connections in our LoadBalancing project (the Master + GameServer applications communicate with each other). As a starting point, have a look at the documentation to understand the concept: http://doc.exitgames.com/photon-server/LoadBalancing/
    You can also have a look at the source code to see an example:
    The "LoadBalancing.GameServer.OutgoingMasterServerPeer" and the "LoadBalancing.MasterServer.GameServer.IncomingGameServerPeer" are a good starting point, - that's the place where we handle communication between Master and Game Servers.

    If you have more detailed questions, please let us know.
    principle of understanding, but how I do not understand
  • chvetsov
    Options
    Take a look at code.
    Use "Find all references" to find all references for ApplicationBase::ConnectToServerTcp.
    You will find how this method is used.
  • I can not find ApplicationBase :: ConnectToServerTcp, they could not help me with the code
    my server consists of two classes:

    [code2=csharp]using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using ExitGames.Logging;
    using ExitGames.Logging.Log4Net;
    using log4net.Config;
    using Photon.SocketServer;
    using System.IO;

    namespace PhotonGame
    {
    public class PhotonServer : ApplicationBase
    {

    protected override PeerBase CreatePeer(InitRequest initRequest)
    {
    //throw new NotImplementedException();
    return new UnityClient(initRequest.Protocol, initRequest.PhotonPeer);
    }
    protected override void Setup()
    {

    var file = new FileInfo(Path.Combine(BinaryPath, "log4net.config"));
    if (file.Exists)
    {
    LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
    XmlConfigurator.ConfigureAndWatch(file);
    }
    }
    protected override void TearDown()
    {
    }
    }
    }[/code2]

    and class
    [code2=csharp]using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Photon.SocketServer;
    using ExitGames.Logging;
    using PhotonHostRuntimeInterfaces;
    //using MySql.Data.MySqlClient;
    using System.Collections;


    namespace PhotonGame
    {
    public class UnityClient : PeerBase
    {
    private readonly ILogger Log = LogManager.GetCurrentClassLogger();
    public UnityClient(IRpcProtocol protocol, IPhotonPeer peer)
    : base(protocol, peer)
    {
    Log.Debug("Connection:" + peer.GetRemoteIP());
    }
    protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
    {
    Log.Debug("Disconnected");
    }

    protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
    {
    Log.Debug("Unknown operation");
    }
    }
    }[/code2]

    the client Unity also has two classes:
    [code2=csharp]using ExitGames.Client.Photon;
    using System.Collections.Generic;
    using UnityEngine;
    using System.Net;
    using System;
    using System.ComponentModel;
    using System.Collections;
    using System.Linq;
    using CustomTree;

    public class PhotonServer : IPhotonPeerListener
    {
    public string Status { get; set; }
    PhotonPeer _peer;
    Login _login;

    public PhotonServer()
    {
    Status = "Disconnected";
    }

    public void DebugReturn(DebugLevel level, string message)
    {

    }

    public void OnEvent(EventData eventData)
    {
    switch (eventData.Code)
    {
    //list of events
    }

    }

    public void OnOperationResponse(OperationResponse operationResponse)
    {
    switch (operationResponse.OperationCode)
    {
    // list of operations
    }
    }

    public void OnStatusChanged(StatusCode statusCode)
    {
    switch (statusCode)
    {
    case StatusCode.Connect:
    Status = "Connected";
    break;
    case StatusCode.Disconnect:
    case StatusCode.DisconnectByServer:
    case StatusCode.DisconnectByServerLogic:
    case StatusCode.DisconnectByServerUserLimit:
    case StatusCode.TimeoutDisconnect:
    Status = "Disconect";
    break;
    default:
    Status = "Unknown";
    break;
    }
    }

    public void Init(PhotonPeer peer, string serverAddress, string applicationName, Login login)
    {
    _peer = peer;
    _peer.Connect(serverAddress, applicationName);
    _login = login;
    }

    public void Disconnect()
    {
    _peer.Disconnect();
    }
    public void Update()
    {
    _peer.Service();
    }

    public void SendOperation(string l,string p)
    {
    _peer.OpCustom(1, new Dictionary<byte, object> { { 1, l }, { 2, p } }, true);
    }

    }[/code2]

    and
    [code2=csharp]using UnityEngine;
    using System;
    using ExitGames.Client.Photon;
    using System.Net;
    using System.IO;
    using System.Drawing;
    using System.Collections;
    using System.Collections.Generic;
    using UsingsRU.Patterns;
    using TreeEditor;
    using CustomTree;

    public class Login : MonoBehaviour
    {
    PhotonServer _photonServer;
    bool _isConnected;
    bool
    sk=false,

    // Use this for initialization
    void Start()
    {
    Application.runInBackground = true;
    _photonServer = new PhotonServer();
    }

    // Update is called once per frame
    void Update()
    {
    try
    {
    if (_isConnected)
    {
    _photonServer.Update();
    }
    else
    {
    PhotonPeer peer = new PhotonPeer(_photonServer, false);
    _photonServer.Init(peer, "localhost:5055", "PhotonIntro", this);
    _isConnected = true;
    }
    }
    catch(Exception ex)
    {
    Debug.Log(ex);
    }
    }
    void OnApplicationQuit()
    {
    try
    {
    _photonServer.Disconnect();
    }
    catch (Exception ex)
    {
    Debug.Log(ex);
    }
    }

    public void DebugMessage(string message)
    {
    Debug.Log(message);
    }
    }[/code2]

    help me I do another server, which would be possible to add to this UDP server

    PS: Вы точно не знаете русский?? Илья - это русское имя
  • chvetsov
    Options
    Hi, vetnabivao.

    Here is international forum, that is why we will contunue talk here in English. But I sent you private message. In private messages we can use Russian.

    So back to your question.

    1. To create new server you need add to your project new class derived from ApplicationBase. You can do this same way as in LoadBalanicing sample done. Take a look at GameServer (GameApplication.cs) and MasterServer (MasterApplication.cs)
    2. Add new application to PhotonConfig.config. check PhotonServer.LoadBalancing-Development.config to see how it can be done

    3. Now we need to establish connection between servers. In terms of LoadBalancing sample we have MasterServer and GameServer. GameServer connects to MasterServer. So what we need to do to make it possible.
    a. we need to know address of master server. You can read it from config like it is done in GameApplication constructor ( GameApplication.cs:68).
    b. now you need to override two methods in your 'GameServer' application: 'CreateServerPeer' and 'OnServerConnectionFailed'. First methods creates peer on your GameServer in case if connection was established successfully. Second one informs you that connection failed.

    c. Finally, you can try to establish connection. if you want to use TCP between servers(prefered way) you call ConnectToServerTcp, if you like more UDP, you call ConnectToServerUdp.
    In our sample we use Tcp connection. You can find how we do this in GameApplication.cs:167 in method ConnectToMaster()

    Btw, when you write server code, you do not care which protocol will be used. Server code is independent from protocol. You define protocol in PhotonConfig.config. Actuallly, you server can use all possible protocols at the same time

    Hope this helps
  • Thanks Ilya! Very good description.

    You said that you can't find the "ConnectToServerTcp()". This was added in Photon 3.2. In previous versions, it was called "ConnectToServer()".
  • Philip
    Options
    I while back I made a little sample serverapp that connects to a photon running lite. See if that helps:
    viewtopic.php?f=5&t=2233&p=10460&hilit=S2STest#p10460
  • and how this is working?
    [code2=csharp]this.retry = new Timer(o => this.ConnectToMaster(), null, this.ConnectRetryIntervalSeconds * 1000, 0);[/code2]
  • It's just a Timer (see see http://msdn.microsoft.com/en-us/library ... timer.aspx ) - to execute the "ConnectToMaster" method again in X seconds if it failed previously. ..