- Home /
UNet does not call OnServerReady on second connect from same machine
Hi, I'm developing a client-server setup with the new Unity Networking (UNet). My server process is a 64bit Linux build and during development I'm repeatedly making connections to the same server process from Unity Editor in my Mac OS-X development machine. I close the client just by stopping Play Mode in Unity Editor.
I've derived BowlingNetworkManager form UNet's NetworkManager and I've got it in the scene. Everything works nicely when I connect to the server process for the first time. BUT when I try to connect second time to the same server process from the same client machine, UNet does not call OnServerReady, and consequently Player prefab won't get instantiated for me. Only solution known to me is to restart the server process, after which I can connect from my laptop again (just once).
I've maxed out debug level in NetworkManager. Here is a server log of a successful connection. That is, the first connection during the lifetime of server process):
ServerController::Start - starting server to address [SERVER-IP]:25100 via NetworkManager
BowlingNetworkManager::OnStartServer - server started, registering handlers for messages...
NetworkServer Created version Current
RegisterHandler id:48 handler:BallStateMessageHandler
...(more RegisterHanlder log entries)...
Server Listen. port: 25100
RegisterHandlerSafe id:35 handler:OnClientReadyMessage
...(more RegisterHandlerSafe log entries)...
NetworkManager StartServer port:25100
Server event: host=0 event=ConnectEvent error=0
Server accepted client:1
NetworkManager:OnServerConnectInternal
BowlingNetworkManager::OnServerConnect - client 1 connected.
Server event: host=0 event=DataEvent error=0
NetworkManager:OnServerReadyMessageInternal
BowlingNetworkManager::OnServerReady - client 1 is now ready.
Ready with no player object
Ready with no player object
NetworkManager:OnServerAddPlayerMessageInternal
BowlingNetworkManager::OnServerAddPlayer - instantiating player NetworkPlayer for client connection 1.
SetClientReady conn 1 already ready
NetworkServer SetupLocalPlayerForConnection netID:0
Adding new playerGameObject object netId: 0 asset ID d94e4ad262b364a3881c49f8a8a7a1b
OnStartServer NetworkPlayer(Clone) (UnityEngine.GameObject) GUID:1
SetLocalObjectOnServer 1 NetworkPlayer(Clone) (UnityEngine.GameObject)
SetLocalObject 1 NetworkPlayer(Clone) (UnityEngine.GameObject)
SpawnObject instance ID 1 asset ID d94e4ad262b364a3881c49f8a8a7a1b
Added observer [CLIENT-IP] added for NetworkPlayer(Clone) (UnityEngine.GameObject)
BowlingNetworkPlayer::Start - client 1 connected.
...(OK now my Unity Editor client has a Player and everything is great)...
...(A bit later I will stop Play Mode in Unity Editor and disconnect will be processed in server)...
Server event: host=0 event=DisconnectEvent error=0
NetworkManager:OnServerDisconnectInternal
BowlingNetworkManager::OnServerDisconnect - client 1 disconnected.
DestroyObject instance:1
Server.SendToObservers id:1
Server lost client:1
I just leave the server running and continue development a bit. Later I'll try to connect to the same server process again by hitting Play in Unity Editor but this time UNet will not call OnServerReady for my connection! Here is the log. Note how client number is 1 again... is this normal?
Server event: host=0 event=ConnectEvent error=0
Server accepted client:1
NetworkManager:OnServerConnectInternal
BowlingNetworkManager::OnServerConnect - client 1 connected.
And there it stops. These should be coming next but they never occur, unless I restart the server process.
Server event: host=0 event=DataEvent error=0
NetworkManager:OnServerReadyMessageInternal
BowlingNetworkManager::OnServerReady - client 1 is now ready.
Any ideas? It is a shame I need to restart server process before I can reconnect... and of course a real client should be able to connect to the server process many times. ;)
I just found out that reconnecting from same client does not work because of my "Advanced Configuration" of Network$$anonymous$$anager. I have enabled advanced configuration and added one QoS channel, which is set to "State Update".
With normal configuration reconnecting work, but if you add 3rd QoS channel with State Update reliability, it won't work anymore.
Actually enabling Advanced Configuration from Network$$anonymous$$anager is enough to break reconnect from same client. You don't need to add any new Qos channels.