having trouble connecting with objective-c

edited May 2012 in Native
Hi,

I've ported a working C++ version of our photon implementation class to objective-c but i can't get it to work (can't receive a successful connect callback, the c++ version works well when connecting). Attached is the skeleton version of the class, just the initialization and a peer status callback.

I have no idea if i missed out anything. Big thanks of anyone could help me out on this.

Thanks! :D

Comments

  • Hi.

    Have you checked, that line [self connect]; actually gets executed?
    Are you calling update() regularly?

    Why are you disconnecting every time, when you are not having anything in your sendQueue?
    1. That seems really ineffective to me in terms of latency.
    2. This way the server will think, that you are a new player, if you do not build in custom server side code to recognize, that it still the same player. This way interaction between players won't work without (potentially a lot) additional server side code from your side, that would not be needed, if you just keep the connection.

    PS:
    I would recommend to not leave the ip of your rackspace server in the source, when posting the source to a public forum.
  • Hello there Sir

    "Why are you disconnecting every time, when you are not having anything in your sendQueue?"
    - this class was intended for an asynchronous game (much like Draw Something) and not a real time game. With that setup, would you still suggest that i keep the connection alive?

    -the rackspace IP that i left there isnt active anymore. thanks for the reminder.

    -yeah the update function is called regularly and the [self connect] gets called. Did i initialized the PhotonPeer correctly? I don't receive the onStatusChanged callback. I assume that everything was setup properly on XCode because the project runs and compiles. This has been bugging me for hours :(

    Thanks for the reply.
  • Do you still have the C++ version around?
    Maybe I can spot the issue, by comparing the not working with the working version.
    mPhotonPeer = [mPhotonPeer initWithPhotonListener:self];
    
    That looks weird: mPhotonPeer is private, so it gets not allocated from outside of the class and it definitely isn't allocated in the source, which you have provided, so you are calling init on an unallocated instance-pointer here, which means, on random memory or just garbage.
    Please try to change it into
    mPhotonPeer = [[PhotonPeer alloc] initWithPhotonListener:self];
    
    Maybe thats the cause of your problems.

    Yes, I definitely would keep the connection alive. Otherwise a player won't be able to receive the info, that other players have made their turns, without doing any action, which would trigger a connect, himself, first.

    I would do it the following:
    Connect, when the player starts the app (in case of an app without a single-player offline mode) or when he clicks on "multiplayer", then keep connection until the app gets closed or he leaves multiplayer-mode and immediately reconnect in case of a connection-loss.

    Now I would only join the game-room in which the player currently wants to make a move and keep the player in a lobby-room when he isn't currently making a move, so that he can receive notifications about updates in the game-rooms there.
  • Hi Kaiserludi,

    i've changed this:
    mPhotonPeer = [mPhotonPeer initWithPhotonListener:self];

    into this:
    mPhotonPeer = [[PhotonPeer alloc] initWithPhotonListener:self];

    and it worked! I wasn't surprised when i missed this because i'm new with obj-c and this was my 1st objective-c class. -my apologies. :)

    my next step is to change the behavior of the class to satisfy your recommendation.

    my deepest thanks. :)
Sign In or Register to comment.