Can a client become a host?

Hi there, this may be a ridiculous question for someone more use to Unity but I was wondering is it possible for a client to become a host?What I mean is that I have created a server that all the clients connect to however if the server disconnect is it possible to make a client on the server the new server.

Well if the server is no longer, it can’t do anything anymore.
Once a player started a server instance, it will need to stop the server instance and connect to another server.
All clients connected to the server will disconnect.
Reconnecting isn’t difficult, you just need to know the new server’s ip address ( which will be alot harder to get )

You’d think the easiest way to set up host migration would be to somehow rig it together in OnDisconnectedFromServer() (because its called on both servers and the clients when the network connection is lost) where you’d have the host pick a host candidate and tell everyone else to connect to him once the connection is lost; but you can’t, because the connection is already lost by the time OnDisconnectedFromServer() fires.

What you can do though is always have a “next-in-line” potential host migration candidate already decided upon and shared to all clients with an RPC. That way, when the connection is lost because the host dropped, all the clients already know the next-in-line’s IP to migrate to. This simple example of course doesn’t account for NAT issues or other complications, like if you actually lost the connection to the server but no one else did (a problem with your own connection), in which case you’d want to try reconnecting to him first.

Yep, but you will loose game state, no way around that.

Yeah, that too. You could probably roll up the game state into something and have the next-in-line candidate have it saved in a persistent object, and he can update all the clients upon connecting to him. All in all, the whole host migration idea is not a trivial thing.

Yes it’s perfectly possible for a client to become the server as other mention though it’s not trivial, the best approach for doing so will depend on the type and size of game you are developing.

One simple approach you can read here http://answers.unity3d.com/questions/30082/host-migration-.html

A more advanced approach would be looking into using Peer to peer networking with something like Badumna that way the game runs across all clients anyway, of course you could tag one client as the server if you needed any points where just one thing happens but mostly that’s not required.

Thanks again everyone I’ll probably look into host migration first and see where I’ll go from there.