IP address and port of a PhotonServer instance in code.

Options
fawnha
edited January 2014 in Photon Server
Is there any way to access the public IP address and port of a running Photon Server instance in code from within that server? I am looking for the IP and port that clients connect to via PhotonPeer.Connect(). I know I set it in the .config file but I don't want to hard code it in code as well. This would require double maintenance. Also, it might not be possible to hard code the IP if we are using a dynamic IP.

Comments

  • Hey,

    it is not possible to access the value from PhotonServer.config in code, but there are some viable options nevertheless:

    - look up the public IP address of the server by a service like whatismyip.com. Check out the Photon.LoadBalancing.Common.PublicIPAddressReader class: the LookupPublicIpAddress() method does exactly that. However, if you have multiple public IPs on your server, it is possible that this method does not return the same IP as your clients use.

    - you can get the exact info per peer: check out the PeerBase.LocalIP + PeerBase.LocalPort properties.

    - you can also write your own XML parser to read the PhotonServer.config file, if you want to get the exact value that is configured in there. Should not be to difficult
    either. :)

    Hope this helps!