The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on Photon Server.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How do you send data to client from the server.

Fedelpiero
2021-06-24 13:25:21

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
2021-06-24 17:04:53

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
2021-06-28 13:15:38

@JohnTube thanks for your answer.

I tried today reading again the code in the doc :

Server :

Client :

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

or the other one with the addCall+=

JohnTube
2021-06-28 15:43:03

Hi @Fedelpiero,

Please read the documentation or finish PUN Basics Tutorial or another YouTube tutorial for PUN2.

Back to top