Sending message to designated peer

Options
billTCP
edited June 2012 in DotNet
I noticed that in the Lite server, client use "peer.OpCustom()" to send message to the server, and then other client can listen to this message, which means this is a broadcast message. The interface is like:
peer.OpCustom((byte)LiteOpCode.RaiseEvent, opParams, true);
If I want to send the message just to some designated peer, for example, a certain person in the same room whose "ActorNr" or "Name" I already knew, how should I send out this message without anyone else receive it? I know if we add the receiver name in the opParams, and each client have a check whether the receiver name matches its own name when receiving every message can solve this problem, but it somehow seems a little unsafe and also produces many waste resources. So, is there a way to just send the message without broadcasting?

Thanks!

Comments

  • Herhangi
    Options
    Hi, you can keep a list of peers connected to the server at the server side and push an event to the designated peer. Like;
    Firstly add a new LiteOpCode as:
    PrivateEvent = 200
    
    Then while sending OpCustom to server add designated peer's ID or Name etc. to the opParams.
    By doing so you will be able to find designated peer on the server and sendEvent(...) to him.
  • billTCP
    Options
    Herhangi wrote:
    Hi, you can keep a list of peers connected to the server at the server side and push an event to the designated peer. Like;
    Firstly add a new LiteOpCode as:
    PrivateEvent = 200
    
    Then while sending OpCustom to server add designated peer's ID or Name etc. to the opParams.
    By doing so you will be able to find designated peer on the server and sendEvent(...) to him.
    So this means that the server side code has to make some change, the original Lite server does not have such function, right?
  • Herhangi
    Options
    Yes, changing server side code will help you to solve this issue. I have not deeply viewed the Lite server but I don't think it has that functionality, as it is only created to show some basic functionalies of Photon Server.
  • billTCP
    Options
    Herhangi wrote:
    Yes, changing server side code will help you to solve this issue. I have not deeply viewed the Lite server but I don't think it has that functionality, as it is only created to show some basic functionalies of Photon Server.
    I see, looks like it only provides some basic broadcasting functions.
    Thanks a lot!
  • Tobias
    Options
    Sorry for the late reply from our side.
    No. You don't have to change Lite.
    Use LitePeer.OpRaiseEvent(byte eventCode, Hashtable customEventContent, bool sendReliable, byte channelId, int[] targetActors).

    Herhangi: You don't need a new operation (these equal RPC methods) for everything you do. Instead, implement a useful set of parameters and make a single function more flexible.

    RaiseEvent has a pretty extensive set of possible parameters. One of those is the targetActors array. It's optional and if not set, the target actors default to "the other players". If you want to send an event only to one player, get that player's actorNumber and create a targetActors array as: new int[] { playerNumber };

    Keep in mind: This is not effective for many targets (each integer actorNumber is 4 bytes to send). Also, there are more options to RaiseEvent which might help, too. Check out the overloads of OpRaiseEvent() in the reference documentation (in the SDK).
  • billTCP
    Options
    Tobias wrote:
    Sorry for the late reply from our side.
    No. You don't have to change Lite.
    Use LitePeer.OpRaiseEvent(byte eventCode, Hashtable customEventContent, bool sendReliable, byte channelId, int[] targetActors).

    Herhangi: You don't need a new operation (these equal RPC methods) for everything you do. Instead, implement a useful set of parameters and make a single function more flexible.

    RaiseEvent has a pretty extensive set of possible parameters. One of those is the targetActors array. It's optional and if not set, the target actors default to "the other players". If you want to send an event only to one player, get that player's actorNumber and create a targetActors array as: new int[] { playerNumber };

    Keep in mind: This is not effective for many targets (each integer actorNumber is 4 bytes to send). Also, there are more options to RaiseEvent which might help, too. Check out the overloads of OpRaiseEvent() in the reference documentation (in the SDK).

    Thank you for let me know this. Lite does have peer 2 peer communication function. I tried your method and it works fine. Before that I planned to modify the broadcast function for this. Thanks a lot!