- Home /
Network sync complicated server-client relationship
Hey everyone
Here is my setup: My clients connect to the server. The server must accept many clients, and does not simulate the world at all. It simply syncs the states across the clients.
When the clients connect they create a synced networkView on itself and the server through RPC calls. Each client does this. The client is the owner of the network view and is broadcasting its state to the server. The server needs to then broadcast this state to the other clients.
The real question is can a networkView (on the client) broadcast to multiple networkViews? Eg, broadcast to all the clients and the server at the same time?
The alternative that I can think of (and have started implementing) is having the server create seperate paired networkViews for all the clients to syncronize the state on the clients, and then the server links (with a script) the data between the paired network views.
Also of note is that the server inst running any world simulations. It is a seperate unity project and it is just exchanging raw data between the clients which do their own simulations.
Best regards... I hope it makes sense :/
You want to boradcast to every networkView on every connected machine ? I assume simply sending an RPC to a single networkView on every connected machine isn't enough (sending an RPC with RPC$$anonymous$$ode = All) ?
If you absolutely need to hit every networkView I'd use a gameobject as a router and have it send (& by implication receive) asll the RPC's then have it distribute the RPC's data to all the game objects in the game (expect a performance hit though depending on hoe often you want to do this).
Answer by W.Walter · Jan 05, 2015 at 10:45 PM
I got it sorted. Unity is awesome :D
Like to share your solution (for future travellers here) ?
I'm actually using two different u city projects, one as server and one as the clients. It works fine except I have to make sure my paired network views get assigned the same view ID by the unity editor otherwise they won't be paired. The server has totally different scripts than the client. Although to send an RPC requires that the sending script contains the RPC, which I have to fix by having a dummy RPC stub to make the RPC send to the server. (The cluents only send RPC to the server,and the server to all the clients)