Photon Server join/create game problem

Hi,

It seems there is a problem joining and creating rooms on a remotely running Photon 3 server. I'm using PUN 1.4 to create the connection. When calling PhotonNetwork.Connect() everything seems to be just fine. I connect to my remote server, but if I try to call PhotonNetwork.CreateGame() or PhotonNetwork.JoinGame(), I'm thrown the following exception:
Error trying to receive. Exception: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host.

  at System.Net.Sockets.Socket.Receive (System.Byte[] buffer) [0x00000] in <filename unknown>:0 
  at ExitGames.Client.Photon.NConnect.Run () [0x00000] in <filename unknown>:0 
UnityEngine.Debug:LogError(Object)
PhotonHandler:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:121)
NetworkingPeer:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:816)
ExitGames.Client.Photon.<>c__DisplayClass2:<EnqueueDebugReturn>b__0()
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:75)

This is followed by
OnFailedToConnectToPhoton, StatusCode: Exception

If I run the Unity client on the same computer as my Photon server, there doesn't seem to be any problems at all in creating and joining games. I can even start up another client remotely, connect, and see the active games that are shown in the lobby. But when I try to join, I'm thrown off and given the exception.

If I have a a Photon server running both remotely and locally, and connect to the remote server, the case is the same as above. But when I try to join or create a game, my client instead connects to the local server and tries to join/create the game there. The odd thing is, that in this case, I don't receive any OnConnectedToPhoton() from the local server or OnDisconnectedFromPhoton() from the remote server. The only way I know that I've connected to and created a game on my local server instead, is that PhotonNetwork.networkingPeer.ServerAddress is set to 127.0.0.1:5056, and that I would have gotten the exception and failed to connect, if the local server hadn't been running.

I'm currently running RC6. The same problem was detected on RC5 and RC5a. Earlier versions haven't been tested.

I'm assuming the problem is some hardcoded test stuff in the Photon3Unity3D library, but I hope you can diagnose the problem soon, as it's a pretty serious problem for us atm that all clients have to be running on the same computer as the Photon server.

Comments

  • A short followup...

    It seems that in NetworkingPeer.OnOperationResponse() the following code is called, resulting in an unreported disconnect.
    case OperationCode.CreateGame:
    {
    ...
    this.mGameserver = (string)operationResponse[ParameterCode.Address];
    this.DisconnectFromMaster();
    this.mLastJoinType = JoinType.CreateGame;
    ...
    }
    

    Furthermore, mGameServer always resolves to 127.0.0.1:5056
  • After a bit more digging, I can see that PUN will only connect to a LoadBalancing instance. It then assumes that the first server that it connects to is a master server. When joining or creating a game, it tries to connect to one of three game servers that exist on the same machine as the master server. However, these are assumed to always be located on 127.0.0.1, resulting in a connection failure if that isn't where the Photon Server (and therefore both master and game servers) are running.

    It seems to always default to the values specified in GameServerSettings.Designer.cs located in the server source under LoadBalancing.
            [global::System.Configuration.ApplicationScopedSettingAttribute()]
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
            [global::System.Configuration.DefaultSettingValueAttribute("127.0.0.1")]
            public string MasterIPAddress {
                get {
                    return ((string)(this["MasterIPAddress"]));
                }
            }
            
            [global::System.Configuration.ApplicationScopedSettingAttribute()]
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
            [global::System.Configuration.DefaultSettingValueAttribute("127.0.0.1")]
            public string PublicIPAddress {
                get {
                    return ((string)(this["PublicIPAddress"]));
                }
            }
            
            [global::System.Configuration.ApplicationScopedSettingAttribute()]
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
            [global::System.Configuration.DefaultSettingValueAttribute("5056")]
            public int GamingUdpPort {
                get {
                    return ((int)(this["GamingUdpPort"]));
                }
            }
    
  • The client disconnects from a master and reconnects to a game server. This is needed to load balance users across machines and get a direct connection.
    The gameserver has a setting for its own "public ip". It's a known annoyance that we currently don't try to find a game-server's public ip automatically (but most servers have multiple ips and it's not always clear which one can be used as game server address).
    You have to edit a config file for that setting. its this file:
    photon-socketserver-sdk\deploy\Loadbalancing\GameServer1\bin\Photon.LoadBalancing.dll.config

    There are two config entries for IPs:
    MasterIPAddress
    and
    PublicIPAddress

    The first is used when you run more gameservers and one master.
    The second one is the game server's address and sent to clients. The PublicIPAddress must be set to any publicly available IP per gameserver. It's different for each deploy.

    we want to automate this, so deploys get easier but we didn't get to it yet
  • I dont have that file, im using photon v2 sdk

    please let me know what i have to change, i have exact error, i tried adding my ip address in the photonserver.config file, and it still did not work.

    <UDPListeners>
    <UDPListener
    IPAddress="xx.xx.xx.xx"
    Port="5055">
    </UDPListener>
    </UDPListeners>
  • tripknotix:
    Please start a new thread for your issue as it's not related. Jacob's issue was with Photon 3 and not 2 and with Photon Unity Networking, not the config.
  • I'm stuck on this same issue.
    If I connect to localhost, everything works great.

    Moving the client off of this machine and I cannot connect.

    I'm using photonControl.exe to run instanceLoadBalancing1.

    I tried to change the config Photon.LoadBalancing.dll.config in Gameserver1 under \deploy\Loadbalancing\Master\bin

    Since my internal ip is 192.168.1.44 I set:

    MasterIpAddress to that value.

    When that didn't work I tried PublicIPAddress. Still no go.

    What exactly do I need to change to make this work? I haven't touched anything else in the baseline setup and cannot find a clear explanation of what to actually do.
  • If your server has the IP 192.168.1.44, then set this as PublicIPAddress in Photon.LoadBalancing.dll.config in Gameserver1 AND GameServer2 under \deploy\Loadbalancing\Master\bin. We run 2 gameservers on your local machine, which is more like the final setup with multiple game servers. Make sure to restart those apps or better: restart Photon.
    Your clients have to connect to 192.168.1.44. Port 5055 is the default one for the Master, 5056 and 5057 are the ports used by the gameservers. All ports must be opened in the windows and any router firewall (if not, a client won't connect simply). Web builds additionally need the policy file to allow these ports (if not, there's a security exception).
  • Okay I made those changes. Gamserver1 and 2 have had their config file PublicIpAddress (In the deploy folders) set to the ip of the machine they are running on.
    I also changed the publicIp of the config in the loadBalancing folder. This was the only way I could connect by running on the local machine.


    I turned off windows firewall as well.

    My machine is 174.24.22.133.

    Partial Config file section of gameservers are as follows:

    <applicationSettings>
    <Photon.LoadBalancing.GameServer.GameServerSettings>
    <setting name="MasterIPAddress" serializeAs="String">
    <value>127.0.0.1</value>
    </setting>
    <setting name="PublicIPAddress" serializeAs="String">
    <value>172.24.22.133</value>
    </setting>



    Section of the Server log shows:

    5584: 10:51:14.902 - Application: "Policy" started in app domain: 5
    5584: 10:51:14.903 - Adding TCP listener on :0.0.0.0: 4530 with a listen backlog of: 150
    5584: 10:51:14.903 - Nagle disabled
    5584: 10:51:14.903 - No TCP inactivity timeout
    5584: 10:51:14.903 - Forcing all applications ids to: "Master"
    5584: 10:51:14.903 - Adding TCP listener on :0.0.0.0: 4531 with a listen backlog of: 150
    5584: 10:51:14.903 - Nagle disabled
    5584: 10:51:14.903 - No TCP inactivity timeout
    5584: 10:51:14.903 - Forcing all applications ids to: "Game1"
    5584: 10:51:14.903 - Adding TCP listener on :0.0.0.0: 4532 with a listen backlog of: 150
    5584: 10:51:14.903 - Nagle disabled
    5584: 10:51:14.903 - No TCP inactivity timeout
    5584: 10:51:14.903 - Forcing all applications ids to: "Game2"
    5584: 10:51:14.903 - Adding TCP listener on :0.0.0.0: 4520 with a listen backlog of: 150
    5584: 10:51:14.903 - Nagle disabled
    5584: 10:51:14.903 - No TCP inactivity timeout
    5584: 10:51:14.903 - Forcing all applications ids to: "Master"
    5584: 10:51:14.903 - UDP address specified as:0.0.0.0 adding listener to each available IPv4 address
    5584: 10:51:14.904 - Adding UDP listener on :172.24.22.133: 5055 with a listen backlog of: 500
    5584: 10:51:14.904 - Adding UDP listener on :127.0.0.1: 5055 with a listen backlog of: 500
    5584: 10:51:14.904 - Forcing all applications ids to: "Game1"
    5584: 10:51:14.904 - UDP address specified as:0.0.0.0 adding listener to each available IPv4 address
    5584: 10:51:14.904 - Adding UDP listener on :172.24.22.133: 5056 with a listen backlog of: 500
    5584: 10:51:14.904 - Adding UDP listener on :127.0.0.1: 5056 with a listen backlog of: 500
    5584: 10:51:14.905 - Forcing all applications ids to: "Game2"
    5584: 10:51:14.905 - UDP address specified as:0.0.0.0 adding listener to each available IPv4 address
    5584: 10:51:14.905 - Adding UDP listener on :172.24.22.133: 5057 with a listen backlog of: 500
    5584: 10:51:14.905 - Adding UDP listener on :127.0.0.1: 5057 with a listen backlog of: 500
    5584: 10:51:14.905 - Adding TCP Policy listener on :0.0.0.0: 843 with a listen backlog of: 150 and routing to application: "Policy"


    And I'm using:


    if (!PhotonNetwork.connected)
    {
    PhotonNetwork.ConnectUsingSettings();
    }

    To connect (from the worker demo)
    Unity Settings are:

    Host Type - SElfHosted
    Server Address - 172.24.22.133
    Port - 5055
    App - Master


    Log from the client still shows:


    (Filename: C:/BuildAgent/work/842f9557127e852/Runtime/ExportGenerated/StandalonePlayer/UnityEngineDebug.cpp Line: 34)

    Error trying to receive. Exception: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host.



    at System.Net.Sockets.Socket.Receive (System.Byte[] buffer) [0x00000] in <filename unknown>:0

    at ExitGames.Client.Photon.NConnect.Run () [0x00000] in <filename unknown>:0
    UnityEngine.Debug:Internal_Log(Int32, String, Object)
    UnityEngine.Debug:LogError(Object)
    PhotonHandler:DebugReturn(DebugLevel, String)
    NetworkingPeer:DebugReturn(DebugLevel, String)
    ExitGames.Client.Photon.<>c__DisplayClass2:<EnqueueDebugReturn>b__0()
    ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
    PhotonHandler:Update()


    When trying to connect from a remote machine.


    If I run on the same machine I can connect fine.


    Any ideas what I should check to track this down? Any other config files or logs to check?
  • Where is the "remote machine" you try to connect from? Which IP does it have?
    Maybe they are not in the same network and simply can't connect?

    Aside from that, it looks like your setup is now ok.
  • Tobias wrote:
    The client disconnects from a master and reconnects to a game server. This is needed to load balance users across machines and get a direct connection.
    The gameserver has a setting for its own "public ip". It's a known annoyance that we currently don't try to find a game-server's public ip automatically (but most servers have multiple ips and it's not always clear which one can be used as game server address).
    You have to edit a config file for that setting. its this file:
    photon-socketserver-sdk\deploy\Loadbalancing\GameServer1\bin\Photon.LoadBalancing.dll.config

    There are two config entries for IPs:
    MasterIPAddress
    and
    PublicIPAddress

    The first is used when you run more gameservers and one master.
    The second one is the game server's address and sent to clients. The PublicIPAddress must be set to any publicly available IP per gameserver. It's different for each deploy.

    we want to automate this, so deploys get easier but we didn't get to it yet

    I've now upgraded our Photon Server to RC8, and it seems you changed something connected to this problem. I changed the PublicIPAddress in the same file as I did for RC7, but this fix isn't working in RC8.

    The problem is exactly the same as the one I described to RC8, except that the fix you mentioned no longer works.

    So my question is now, what should I do to get RC8 to work?
  • Hi, I'm not sure if this is the same problem but i cant join create any game with my self hosted photon server, I've it running on my host (Amazon EC2) I'm trying with photoncloud api from asset store but only connects to the lobby then when i try to a create room i got this after few seconds OnFailedToConnectToPhoton. StatusCode: TimeoutDisconnect

    I already edited gamerserve1 and 2 configs to have the public ip of my host.
  • Have you removed the RC7 service before installing the rc8 one?
  • RC8 is the first version I've tried, so nobody knows about my issue?
  • Kaiserludi wrote:
    Have you removed the RC7 service before installing the rc8 one?

    yep
  • Is it possible to make configuration in which GameServers will accept connections from both internal and external clients?

    Server with Photon has internal IP 192.168.100.150. Local clients are in the same subnet.
    I configured port forwarding on my router to map connections to external IP to the Photon server.
    Clients are connected via DNS record. For clients in local network it maps to internal IP and for internet clients to external.

    If I set in config PublicIPAddress to the 192.168.100.150 - internal clients succesfully connected but external can't connect.
    And vice versa if I set PublicIPAddress to my internet IP or delete it at all for automatic detection.

    Is it possible to configure Photon for accepting both internal and external clients?
  • Does your router not allow you to just connect to the external ip from within the lan with the router then being smart enough to short circuit the message straight within the LAN?
  • Well, it's under FreeBSD.

    I tried to use redirect rules. It routes requests from internal clients to the photon server (by rewriting src IP) and photon server replieys correctly.
    But client is going mad becase he sends request to the external IP but recieves responce from internal =).

    The other possibility is to configure NAT on the router so it will proxing packets between clinet and server but I think this os not to good from the archtectural point of view.
  • Has this ever been figured out? I'm having the exact same issue. Cannot log on server via it's "external ip", only locally.
  • I think this depends on your router's setup or your ISP. Your routers and machine has to be setup to be reachable, when it's the client who initiates the connection...

    Please post details in the Server forum. Let us know if you tried from another machine, too.
  • edited December 2016
    I'm guessing this is not yet automated? I got this error as well.
    I tried to change the Photon.LoadBalancing.dll.config but did not work:



    (Fields in red are my public IP, and not the default "127.0.0.1")

Sign In or Register to comment.