[SOLVED] Get ping of other peers

The whole answer can be found below.

Please note: 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! And we offer you support through these channels:

Try Our
Documentation

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

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.

[SOLVED] Get ping of other peers

scadieux
2013-01-16 18:42:27

Good day,

I'm currently working on trying to figure out a clever way to know the ping between other players and the PhotonCloud server.

My first approach was to compute it in OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) using the following formula: ping = (int)((PhotonNetwork.time - info.timestamp) * 1000 - PhotonNetwork.GetPing());

But the PhotonNetwork.time - info.timestamp part resturn invalid results. I was hoping this would return me the time between the message has been sent and now but the results are way too much unstable.

I could use room properties and each user would publish it's ping to the room but that's an overhead that would be the same as sending an RPC to other players to publish the ping.

Any suggestions?

Comments

rokawar
2013-01-16 21:57:53

why not like that? :

Hashtable PlayerCustomProps = new Hashtable();

PlayerCustomProps["Ping"] = PhotonNetwork.GetPing();

PhotonNetwork.player.SetCustomProperties(PlayerCustomProps);

and for check all players ping :

foreach (PhotonPlayer player in PhotonNetwork.playerList){

Debug.Log(player.customProperties["Ping"].ToString());

}

No overhead and simple.

scadieux
2013-01-16 22:23:18

Yes, that's what I meant by room properties I guess I didn't know the exact name for it :)

Well that's pretty much the equivalent of sending an RPC right? I'm worried it might be a performance issue :s

Anyway thanks for the code :)

rokawar
2013-01-16 22:37:47

Hum personaly i use 6 player.customprops(Team/kills/deaths/Clan/Level/Ping) per player without any problem.

After i don't know if the customprops are counted on the MSG per room like a RPC.

Only tobias can answer that i think.

Tobias
2013-01-17 09:16:17

Maybe a short property doc would be helpful:

Player properties are great for something like ping or skill, name, etc. Anything that's not changing on high frequency and is an absolute value (cause only the last set value is stored and sent by server).

The values you set are being sent, so in best case you only set props that have new values. The Hashtable containing the properties in the clients will merge the new values with the existing ones and set their values. To delete a property, set it's value to null.

Setting and receiving properties counts as message each. You can set several values in one call though.

scadieux
2013-01-17 20:58:58

Thanks, that makes sense perfect!

Back to top