Photon Realtime, how do I start?

Hello,
I am trying to create an online game, where the users play in turns. I downloaded the demo code, but I am a little bit lost.

I believe that I need to load the Chat, Photon and Common libraries. Do I also need to load the LoadBalancing library or is it loaded by the other 3 libraries?

Could someone direct me to a site with instructions on how to start and build my app? I need users to be able to login to the lobby, create and join rooms, etc.

Thank you

Comments

  • For example, in the Photon library I see the class EGLitePeer. What does this class do? How do I use it?
  • I found this doc
    https://doc.photonengine.com/en-us/realtime/current/getting-started/realtime-intro

    and based on this, all I need to use the LoadBalancing library. Am I correct? If yes, what are the other libraries used for?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited October 2019
    Hi @Vasilis,

    Thank you for choosing Photon!

    What Photon Realtime SDK are you using?
    For most cases, Photon Realtime client SDK includes the LoadBalancing Client API + Photon client library.
    What other libraries are you referring to?

    Photon Chat API is optional.
    It uses the same client library as the LoadBalancing Client API but it connects to a different server application.

    You may find some answers on our FAQ here.
  • Hi @JohnTube,

    I saw that your demos use different libraries. I do realize that the LoadBalancing client is the one I need. But, your demo does not have all the methods that I could possible need. For example, I can not find a method to send a message (both private and to all users in a room)

    Actually, why don't you create a wrapper for your libraries? Why do I (and the rest of us) have to create the wrapper?
    Thank you
  • Hi @Vasilis.

    Literally every one of our demos demonstrates how to send a message.
    The method for doing so is EGLoadBalancingClient::opRaiseEvent().

    I assume that you use the Photon Objective C client libraries (you have mentioned the class EGLitePeer, and the Objective C one is the only client API in which our classes have an EG-prefix in their names).

    For the future: please metnion which Client SDK you are using, so we don't have to guess if you are referring to the C#, C++, objective C, Lua or JavaScript Client APIs.
    Which Client API you are using is often the most important piece of information to properly answer your questions.


    Actually, why don't you create a wrapper for your libraries? Why do I (and the rest of us) have to create the wrapper?

    You don't have to do that. There is no need for a wrapper, so why would you want to create one?
    Vasilis said:

    I found this doc
    https://doc.photonengine.com/en-us/realtime/current/getting-started/realtime-intro

    and based on this, all I need to use the LoadBalancing library. Am I correct? If yes, what are the other libraries used for?

    You either use the LoadBalancing library (if we want to communicate with Photon Realtime or with self-hosted Photon servers that run the LoadBalancing application) or the Chat library (if you want to communicate with Photon Chat) or both of them.
    The LoadBalancing and the Chat library both sit on top of the Photon library, which provides the lower level networking that they are based on. You usually don't interact much with Photon library yourself directly, but you still need to link against it, as LoadBalancing and Chat depend on it.
    The Common library contains stuff like data containers, serialization, etc. and the Photon library depends on it. Hence you also need to link against that library.
  • Hi @Kaiserludi,

    I apologize for this. Yes, I am testing the obj-c client. By wrapper I mean code that handles all the communication with the Photon server. Now, I have to copy your demo code and extend it so that it has all the methods that I would need in my game (i.e., create room, join it, send messages -private and to the room, exit a room). I know, it is straightforward, and one may say that I am lazy developer that I ask for this. But, it will eliminate all my mistakes due to lack of experience. I should focus on the logic of my game and not on the logic of the Photon engine.

    Now, I am also looking at the demos for the Android ... I am totally lost here
  • Hi @Vasilis.

    Now, I have to copy your demo code and extend it so that it has all the methods that I would need in my game (i.e., create room, join it, send messages -private and to the room, exit a room).

    No, you don't have to do that.
    If you look at the demo code, then you see that all it really does it calling the according functions in the API.
    EGLoadBalancingClient has among other functions opCreateRoom(), opJoinRoom(), opRaiseEvent() (for sending messages to other clients inside the same room), opLeaveRoom(). You can use them right away (don't forget to call connect(), disconnect() and to regularly call service(), though) from your game code without copying or enhancing any demo code. The demo code just shows how to use them.

    Regarding Android:
    I will respond in the separate forum thread that you have opened on that topic.
  • Hi @Kaiserludi,

    What I did not mention is that I am switching from a different product to your product. Because of that, I have to follow your product's logic. I found your product far more versatile and easier to debug it, if something goes wrong. But, their product was far easier to use it. All I had to do was to import the framework and implement the methods in the protocols.

    But, the thing that is troubling me the most is that I can not find a good documentation for the API. I have found the list of classes, but that does not help me. I need to know what each method does, when it is called, etc.

    For example. I found that when I am in a room, I can not create another room. Also, when I create a room, by calling the opCreateRoom method, the joinOrCreateRoomReturn method and not the createRoomReturn method is called.

    Also, according to the documentation, by default all players are connected to the Lobby. But, the can not interact. They can not send messages. Why is that?
  • Hi @Vasilis.

    But, the thing that is troubling me the most is that I can not find a good documentation for the API. I have found the list of classes, but that does not help me. I need to know what each method does, when it is called, etc.

    You are using the Android NDK Client SDk as well, if I am correct. You can find the C++ Client API reference at https://doc-api.photonengine.com/en/cpp/current/, which has some more in-depth information than the objective C one. The objective C Client works the same way aside from differences that are caused directly by the differences between the two languages.

    I found that when I am in a room, I can not create another room.

    This is by design. One Client instance can only be active inside one room at a time. However you can leave a room with the 'willComeBack' flag set to true to rejoin it later one, which is useful if your game is turnbased and you want to support the option of players playing a turn match B while they wait for their opponent to make their turn in match A.

    Also, when I create a room, by calling the opCreateRoom method, the joinOrCreateRoomReturn method and not the createRoomReturn method is called.

    It works correctly (the createRoomReturn method is called) for me. Please provide detailed reproduction steps.

    Also, according to the documentation, by default all players are connected to the Lobby. But, the can not interact. They can not send messages. Why is that?

    Because it is a lobby and not a chat room. If you want players to be able to interact with each other outside of rooms, then you can do so via Photon Chat.
  • Hi @Kaiserludi,

    One last question, and I promise I will shut up.
    When I send an event, I call the method opRaiseEvent with certain parameters.
    This method returns a boolean. Is this enough to consider that that event has arrived at the Photon cloud server? At the Photon C++ doc link that you posted above, it says that that method will call the callback PhotonListener::onOperationResponse(). In obj-c code I believe that the callback is suppressed for events.
  • Hi @Vasilis.

    it says that that method will call the callback PhotonListener::onOperationResponse().

    It says so in the doc for Lite::LitePeer::opRaiseEvent(). You should rather look at LoadBalancing::Client::opRaiseEvent(). Lite is deprecated and should not be used anymore.

    You don't get an operation response for the raiseEvent operation.

    This method returns a boolean. Is this enough to consider that that event has arrived at the Photon cloud server

    No.
    It only tells you if the event could successfully be queued for sending to the Photon server.
    The actual sending won't happen before the next service() call. Unreliable messages can get lost on their way. With reliable messages as long as you continue to call service() regularly the message will either reach the server or the client will inform your app that it got disconnected.
  • Hi @Kaiserludi,

    a reliable message is the one that arrives at the server or it also arrives at the clients?

    Also, which callback will inform me if the event is delivered? You told me how to monitor for errors but, how can I monitor for successful deliveries?
  • Hi @Vasilis.

    A reliable message is guaranteed to arrive at the other client as long as both clients are connected.

    There is no callback to inform you about event delivery. For unreliable events it should not matter and with reliable events you either get a callback to inform you that you have been disconnected or an event that informs you that the other client has left the room or you can be sure that the event has arrived.
  • Vasilis
    Vasilis
    edited October 2019
    Hi @Kaiserludi,

    lets consider the following example
    I send three messages to a room. After the 3rd message, I get a callback that I am disconnected or that the other player(s) has left the room. Which of these three messages has actually arrived at the other clients?

    Once I send an event do I need to wait for a few seconds before I send the second one?

  • Hi @Vasilis.
    For normal in game messages it should not be relevant, which of those messages has still arrived before the disconnect as you are disconnected anyway. For the rare cases that it does matter, you can of course simply let the other client send acknowledgements for receiving those particular messages.
  • Hi @Kaiserludi,
    This adds an extra level of complexity to the game logic. A callback from your side would fix this
  • Hi @Vasilis.

    In the vast majority of apps for either all or nearly all messages that are sent via Photon in the such a callback would be unnecessary overhead.

    Maybe you could explain the scenario in which you think that you need such a callback.
  • Vasilis
    Vasilis
    edited October 2019
    Hi @Kaiserludi,

    You can consider my above example. In that case, it would be extremely useful to know if the other players have received my first message before I send the second one, etc.
    Do not consider those messages as actual messages, but moves. They have to arrive at a given order. If not, the app will not work properly.
  • Hi @Vasilis.

    Messages will always arrive in the order in which they have been sent. In case that a reliable message gets lost on its way and needs to be repeated, the receiving client will automatically hold back all messages that it receives that have been sent after that message, until it has also received the missing message, so that it can forward the message it to the app in the correct order. Note that the order of messages is per channel.

    You can explicitly specify the channel on which a messages should be sent. All messages that depend on each other should be sent on the same channel to guarantee their order of arrival. Messages that are independent from them can be sent on a different channel so that messages on channel B don't have to wait if a message on channel A needs to be repeated and vice versa.

    If a client actually looses it's connection, then either the game is over for it anyway, or it needs to reconnect and rejoin the room. In that case the clients can just as a first message after the rejoin inform each other what they think was the last move. That way the clients can check if a move is missing and can resend it.

    You might also want to read about cached events in our documentation: Events can be stored in the room cache so that they can automatically be resent to clients, that join the room. Pay attention to remove moves from the cache once yo can be sure that all clients have definitely received them (i.e. if the logic of the game dictates that client A won't make a move until it has received all previous moves, then you can be sure that this client has received moves 0-31 when it sends move 32), so that the cache does not become too huge. You don't want a client that gets disconnected from a game that has already been lasting for a while, to re-receive thousands of past moves on rejoining the room, just because it might have missed the last 1 or 2.
  • Vasilis
    Vasilis
    edited October 2019
    Hi @Kaiserludi,

    Messages will always arrive in the order in which they have been sent. In case that a reliable message gets lost on its way and needs to be repeated, the receiving client will automatically hold back all messages that it receives that have been sent after that message, until it has also received the missing message, so that it can forward the message it to the app in the correct order. Note that the order of messages is per channel.
    I send a reliable message. It is queued, but the opponent has lost connection. I do receive this event, and because I stop sending the remaining messages. Will that first message be delivered when the opponent reconnects and rejoins the room?
  • Hi @Vasilis.
    No, you will need to resend it or to add it to the eventCache for automatic resending on rejoins (the opponent can remove it again from the cache when it has received it, so that it does not get bombarded with tons of cached events that is has already successfully received in the past).
  • Vasilis
    Vasilis
    edited October 2019
    Hi @Kaiserludi ,

    That helps a lot. Thank you