RPC vs RPC via server.

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.

RPC vs RPC via server.

dontonka
2014-08-08 03:08:58

Hello, I've read the documentation, even look into Photon code, but this topic is still not 100% clear :).

So when we call an RPC using a none server target (so using any except AllViaServer and AllBufferedViaServer), this network communication will not reach the server is that correct? If so, this means the clients are connected Peer-To-Peer? What is the network protocol handling this, is it UDP or TCP? For servers target, it seems clear it reach the server correct?

Don T.

Comments

Tobias
2014-08-08 15:23:07

Ignore the server for PUN. The server does not exist in the PUN client side. It is transparent and just forwards events from one client to the others and does some caching of events. You always communicate through the server but it's not visible for the clients.

All clients are equal. The Master Client is selected as "the player with the lowest ID" and not really special. It just takes control of the GameObjects no one else controls.

What is a server target?

dontonka
2014-08-12 00:59:51

Ok thanks Toblas.

What is a server target?

I was referring to AllViaServer and AllBufferedViaServer. So what is the difference beetween AllViaServer and All target when using PUN (I'm referring to the enum PhotonTargets)?

Cheers, Don T.

Tobias
2014-08-12 08:57:23

The difference between AllViaServer and All target is the path that the RPC takes for the local player. With "All", PUN sends the RPC to the others and executes it locally. This saves the roundtrip and some traffic but the execution order is different locally than for everyone else. With "AllViaServer", PUN asks the server to send the RPC to everyone, including "this" client. PUN does not use a shortcut and execution of the RPC is in the same order as on other clients.

MrVentures
2021-03-30 01:05:06

Hey @Tobias I am curious why the asteroids example would use this line:

photonView.RPC("Fire", RpcTarget.AllViaServer, rigidbody.position, rigidbody.rotation);

Wouldn't we want to use RpcTarget.All in this case, since a round trip delay every time the player fires would be noticeable? You mentioned "the execution order is different locally than for everyone else", what is the risk associated with this if I were to say... replace the above line with RpcTarget.All?

Tobias
2021-04-01 13:50:11

Yes, the lag could be noticed easily. The Asteroids demo doesn't solve shooting very .. precise.
The assumption is that you get about the same timing for everyone, if all players (including the shooter) fire on receiving the event.
You could / should add a local prediction of what's going on: Fire a shot immediately and move it accordingly. Then you have to align / correct your local prediction, when the event arrives.
If each player does this properly, the results are the same on all clients.

IBX00
2022-12-07 18:49:24

@Tobias

Sorry to ask on this old thread but can you please elaborate on this part of your answer:

"the execution order is different locally than for everyone else"

Tobias 2014-08-12T08:57:23+00:00
The difference between AllViaServer and All target is the path that the RPC takes for the local player.

With "All", PUN sends the RPC to the others and executes it locally. This saves the roundtrip and some traffic but the execution order is different locally than for everyone else.

With "AllViaServer", PUN asks the server to send the RPC to everyone, including "this" client. PUN does not use a shortcut and execution of the RPC is in the same order as on other clients. What order of execution are we talking about?

Let's take my example for now.

Suppose we have a room with 3 players: A, B, and C.

"A" fires an RPC on its own photon view. What order are we talking about then? Is it the order in which B and C will receive the RPC? And how will it be different in these two cases(RpcTarget.All vs RpcTarget.AllViaServer)? I know that in the case of RpcTartget. All, the execution will be immediate on whomsoever fires the Rpc.

Sorry if it sounds like a dumb question but I solved an irritating bug by just changing the Target from All to AllViaServer and I'm simply unaware of why it worked.

Tobias
2022-12-21 15:08:56

Sorry for the late reply.

When you use Target.All, the client on which you call the RPC will send it and immediately execute it locally. Meaning the others will execute it after a full roundtrip time while the local client already changed state.

When you use Target.AllViaServer, the RPC will be sent to all clients, including the one that called the RPC locally. All clients in the room get the RPC via event and also the local one will wait the roundtrip before executing the actual RPC it called.

Makes more sense?

Back to top