How do you send data to client from the server.

Options
Hello,

I am very sorry to answer this as it looks like I don't understand anything, or that I didn't bother trying to gather the info myself. I honestly read the Server documentation multiple times and tried to find on the forum, but I do not see something simple to start building around, everything is only for client side which is really easy indeed, but it's not what I am looking for.

I setup Unity with PUN, and I downloaded and setup a C# project with a custom plugin following the step by step.

so right now I have

```
public override void OnCreateGame(ICreateGameCallInfo info)
{
this.pluginLogger.InfoFormat("OnCreateGame {0} by user {1}", info.Request.GameId, info.UserId);
info.Continue();
}
```

which works, my user create the room and the logs appear.

From here I am stuck, I have some game logic already on the client, and I know what to do on my server, but I do not understand how they communicate. It might be me, but the documentations is a bit unclear on this point but hopefully there is a lot of TestPlugin where we can get some interesting info, thank you for that.


- is `PluginHost.BroadcastEvent` for broadcasting to multiple actor but also a single one ?

- Should I use only event ? I saw that there is 199 event possible, so I should bind an event to each of my operation ? wouldn't that make a gigantic switch that would dispatch to appropriated events ? Is it always

- what is `PluginHost.SetProperties` is it to set property to an actor but on the server map only ?


If it would be possible to have a very simple implementation of client send data to server, server process the data and respond to that client, it would help me a lot getting started.

Thank you, and sorry again.

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Fedelpiero,

    Thank you for choosing Photon!

    Very good questions.

    - PluginHost.BroadcastEvent name is misleading. It's the equivalent of RaiseEvent from client side. Use it to send custom events to one or more actors.

    - There are no custom operations (if you want something operation-response async. similar: instead use custom event code for client to server and another event code for server to client). You can use custom events or room/actor properties. You don't have to use as many events, do you need all those?

    - PluginHost.SetProperties is the same as SetProperties client side, use it to set actor or room properties.

    You can send data to clients inside plugin hooks methods, from a timer or from a HTTP response callback.

    The manual and the FAQs pages have more info.!
    Let us know what you tried and if you have specific questions
  • Fedelpiero
    edited June 2021
    Options
    @JohnTube thanks for your answer.

    I tried today reading again the code in the doc :


    Server :

    public override void OnCreateGame(ICreateGameCallInfo info)
            {
                this.pluginLogger.InfoFormat("OnCreateGame {0} by user {1} with actor {2}", info.Request.GameId, info.UserId, info.Request.ActorNr);
                info.Continue();
                this.PluginHost.BroadcastEvent(new int[] { info.Request.ActorNr }, 0, 0, new Dictionary<byte, object>() { { 245, "test" }, { 254, 0 } }, CacheOperations.DoNotCache);
            }
    


    Client :

        private RoomController()
        {
    
            this.photonView.AddCallbackTarget(this);
        }
    
    
    
         public override void OnJoinedRoom()
        {
            base.OnJoinedRoom();
            Debug.Log("Room Joined");
        }
        public void OnEvent(EventData photonEvent)
        {
            Debug.Log(photonEvent);
        }
    


    But nothing ever recieved althougt I do create a new room and the `Room Joined` works

    Could you help only on this ? thanks !

    I saw post like this

    https://forum.photonengine.com/discussion/comment/36593#Comment_36593
    or
    https://forum.photonengine.com/discussion/13745/raiseevent-onevent-not-firing


    and already tried to add
    public void OnEnable()
    {
        PhotonNetwork.AddCallbackTarget(this);
    }
    
    public void OnDisable()
    {
        PhotonNetwork.RemoveCallbackTarget(this);
    }
    

    or the other one with the `addCall+=`
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options