I need an equivalent to Network.isServer using Unity’s new multiplayer way of doing things (since the old one is going to be obsolete in the near future).
Right now, Network.isServer always yields “false” even on clients that are servers so the new way is definitely not compatible with the old.
I need a way for a MonoBehavior to ask if the application is connected and whenever or not it’s the one hosting the game. NetworkServer.active’s description seems too vague to do the job especially since NetworkClient.active is described to yield “true” whenever a client is active… and I don’t want to turn every single script into a NetworkBehavior whenever I want to do a simple check.
Does NetworkServer.active yield EXACTLY the same results as Network.isServer used to? If not, what does?
Thats the confusion okay so heres how it works. If you start the network it will be listening on that device… As long as there isnt a listener on the device it will return false.
for example device 1 starts NetworkServer.Listen(someport);
on this device when you do NetworkServer.active its true because the server is running
device 2 NetworkServer.active will return false because this device isnt listening…
if you want to check if the server is available the only way to do that is to try and make the connection from device 2 to device 1 and if it connects then you know the server is running if it doesnt well the server isnt running…
I have created a mini HttpServer for a backend request in my Cross.Net Asset for this exact issue, As it takes to long to figure out if its running or not. With the HttpServer in place you can request quite quickly.
(You might also want something along these lines)
In order to use this method you have to inherit NetworkBehaviour to your class
Example class someclass : NetworkBehaviour{
if both devices are connected together you can also do if(isServer).
or you can check if its the client by if(isClient)