Transitioning from PUN to Photon Server

Options
82apps
82apps
edited April 2014 in Photon Server
I have a game that uses Photon Unity Networking successfully. I'd like to also implement Photon Server support so that users can host their own servers. But it's really unclear to me where to start and how much of my existing networking code I can re-use.

First of all, is it even possible to add Server support within my existing PUN code (with maybe a different connection method), or do I need to rebuild everything from scratch?

If it is possible, what's the best tutorial for me to start with?

Very specifically: I've got Photon Control running, how would I connect to my local IP?

Comments

  • Hello 82apps, im newbie with photon but for what i undestand, you need to launch the server first via C++. You then need to know the Server adress and port to give that to others players. I never code this myself but i understand how it works.

    You can see the settings in PhotonServerSettings.Asset , there's "PhotonCloud" and "SelfHosted".

    About reusing your network code, well, if it is already working i dont see why not. A server is a server, inside a datacenter or in some bassement self hosted.

    Of course things are not that simple but i hope to reach some light on your "where to start".

    I found this, maybe it helps: viewtopic.php?f=8&t=800
  • 82apps
    Options
    I was able to set this up, thought I'd update my post with my findings.

    The first step is to set up Photon Control on your computer, which is explained well here: https://www.youtube.com/watch?v=8n5R1cDuYUY

    What's not so well explained in order for your PUN application to work, you need to find "LoadBalancing (MyCloud)" within Photon Control and choose "Start Service". If you just use the Default service, you will get authentication errors (like this: "Authentication failed: 'Unknown operation code 230' Code: -1").

    Within your code, just change the PhotonNetwork.PhotonServerSettings like this:

    PhotonNetwork.PhotonServerSettings.HostType = ServerSettings.HostingOption.SelfHosted;
    PhotonNetwork.PhotonServerSettings.ServerAddress = address;
    PhotonNetwork.PhotonServerSettings.ServerPort = 5055;

    Then connect like you normally would, e.g. PhotonNetwork.ConnectUsingSettings()

    Note: you can get the server address from PhotonControl's Game Server IP Config menu option.
  • 82apps
    Options
    One thing came up that is very confusing - I noticed this morning that I was able to connect to a local Photon server (and even join it from another machine) - but I never started up PhotonControl or the LoadBalancing services. How is this possible? Does it auto-start the server somehow once you've run it once? Or was I doing it wrong all along?
  • Kaiserludi
    Options
    Hi 82apps.

    Yes, if you have installed it as a service form the Photon Control, then that service will get autostarted on a restart of the computer, but if you have only started it as an app, then you will have to manually start it first. When you go live with your app, its advisable to run Photon as a service, so that in case that your server hardware goes down, Photon will automatically restart, when the hardware restarts - because the need for manually starting it would increase downtimes in such cases. For development you may prefer running Photon as an app, especially when you are switching between different Photon Server versions for different games on the same machine - with a service you would always have to deinstall a service from one sdk before attempting to run one from a different sdk.