Should I use Photon Realtime for my peer to peer crossplatform play?

mantracker
edited December 2017 in Native
Hi, I am currently looking into integrating UE4 with Photon. Our UE4 game will be cross platform, and rather than having a centralized server, we intend to keep to a peer-to-peer architecture. One of our players will act as a host, while other players join as clients.

We intend to use Photon for match making, and I just want to understand better how Photon is going to handle the match making part and how UE4 will use this. From what I understand from the matchmaking guide, and the UE4 demo project, I just make bunch of calls like opJoinRoom or opCreateRoom and such and rooms are created.

However, I was more expecting that when one of the clients tell the match maker to find a game to join, the match maker would return the host's IP address, and then the client would probably use UE4 native calls to join that IP address. But the below code doesn't seem to return an IP address:

virtual void joinRandomRoomReturn(int localPlayerNr, const ExitGames::Common::Hashtable& gameProperties, const ExitGames::Common::Hashtable& playerProperties, int errorCode, const ExitGames::Common::JString& errorString);

(There is no IP address returned here)

How exactly does clients join the host's rooms?

Comments

  • Kaiserludi
    Kaiserludi admin
    edited December 2017
    Hi @mantracker.

    As I have explained at http://forum.photonengine.com/discussion/comment/37044/#Comment_37044, the client that you want to be the host would just send it's IP-address to the other clients inside that room. You could either send it by opRaiseEvent() or set it as value of a room property. You even could set that room property to be visible in the lobby, so that other clients would not even need to join the room to see the IP-address.

    Photon does not send the IP of the host on its own as this information is not necessary for games that are hosted on the server (which is the most common use case) and therefor would waste bandwidth for no reason for games that do not need it.
  • mantracker
    edited December 2017
    Hi @Kaiserludi

    Thanks for your answer above! I have another question in regards to NAT tunneling. I understand that Photon is a client-server architecture, but for my P2P Unreal game, I'd like to understand how Photon handles matchmaking when both of the game's players are behind the same router.

    In this case, if I were to send the public IP for the players, they would be same and I can't have the client join the server's room. So my question is, if both players are behind the same router, what are the steps I need to take to have these 2 exchange IP addresses so they can play together?
  • Hi @mantracker.

    Photon matchmaking does not know if those players are behind the same router and it does not care and won't treat them differently than other players.

    A possible approach to this scenario would be the following:
    Let your code send the public IP and the local IP of the client to the other player through Photon.
    The receiving clients then so a string compare of the hosts public IP with their own public IP and if the two strings are equal to each other, then they would connect to the provided local IP, otherwise to the provided public IP of the host.
  • Hi @mantracker.

    Photon matchmaking does not know if those players are behind the same router and it does not care and won't treat them differently than other players.

    A possible approach to this scenario would be the following:
    Let your code send the public IP and the local IP of the client to the other player through Photon.
    The receiving clients then so a string compare of the hosts public IP with their own public IP and if the two strings are equal to each other, then they would connect to the provided local IP, otherwise to the provided public IP of the host.

    That sounds like a great solution. Thanks I'll try it out!
  • mantracker
    edited December 2017
    Hi @Kaiserludi

    Does Photon offer anything in the way of port forwarding? With Photon acting as a master server, I read that NAT punchthroughs should not require me to do port forwarding. I don't quite understand how that works.

    Generally speaking, I am passing public IPs between players, but I would like to set it up such that players don't have to mess with their routers to connect to their friends online. I know that there are tools like uPnP that can do things like this, but I am wondering if Photon can help with port forwarding.
  • Hi @mantracker.

    No, Photon does not help in this regards.
    One of the main reasons for client-server solutions is that it avoids these kinds of issues that come with p2p approaches. So as photon is a client-server solution, it does not have to deal with these issues.
    When you do a p2p connection through Unreal networking, then it is up to you (or to Unreal networking) and the user to make sure that players can connect to each other.
  • mantracker
    edited December 2017
    Hi @Kaiserludi

    This is more of a networking problem than a Photon related problem, but since I cannot use Photon for NAT punchthroughs or anything, what would be the best way for 2 clients to connect when they are both behind NAT?

    If client A has a public IP and private IP, and client B has a public IP and private IP, then for client A to connect to client B, it has to first open a connection to B's public IP then to specify B's private IP as well?

    Unreal doesn't seem to be able to help with NAT traversal. Is it possible to use Photon as a relay server or something to setup a punchthrough? Or am I out of luck and have to integrate something like uPnP, RakNet or some other third party library to do this?

    Thanks
  • Hi @mantracker.

    It is possible to use Photon as a relay server, but that would mean switching your networking code form UE networking to Photon, hence rewriting all your networking code (or duplicating all networking code and maintaining two different solutions, if you would prefer to continue to use p2p instead of a relay server when possible). You don't need to write your own server side code or to host and maintain servers for this. You could just use Photon Cloud.

    So yes, this requires quite some work by you on your networking code, but I don't think that the alternatives that you have mentioned (integrate something like uPnP, RakNet or some other third party library to do this) would require a lot less work.