Found mega networking problem, when Unity looses focus, the heartbeat stops… HUGE problem, I mean HUGE problem, did I mention HUGE problem?
Every single game loop, at the start of the loop, a network heartbeat MUST be triggered, absolutely MUST BE TRIGGERED. This states that the Unity networking is not in its own thread, instead it is a child of the single threaded model of Unity… Let me go back to the statement, VERY HUGE PROBLEM.
On top of that, I have yet to detect the triggered hearbeatsend command from the client when running as a client for an empty echo heartbeat. Not so huge of a problem but still a major problem. Guys, come on, we users have absolutely zero power here on this, I do mean zero power. Unity has this coded internal as part of the engine, Even though we can do a server create, we do not control the heartbeats, you do, this is number 1 on Raknet ‘A MUST DO’ list.
This has to go in 2.6, or a 2.5.2, this is a HUGE problem! Either that or add the heartbeat commands to our list of commands on the base Network class you have. I’ll go back to the major statement of HUGE PROBLEM…
This is part of the RakPeerInterface and it MUST exist and it MUST be properly used. This is pretty much the control of checking for and acting upon packets.
I would have never ran across this if I hadn’t started to help people today with the internal network configuration in unity based on RakNet. You have overlooked a completely major component of raknet, and I do mean major.
The application has to have a background thread that Raknet runs on that is seperate from the main thread so that you can loose focus on the main application and not loose raknet from running. (I’ll now reffer to huge problem). When the client on the same machine in testing, connects to the server on the same machine for testing, the LOG does not show the connection as long as the client has focus, when the client looses focus and the server gains focus, the log then shows that the client connected, AT THAT POINT the client is reset because the thread has frozen state, so when the client gains focus again, its current PORT is 0 instead of its connected port to the server.
HUGE problem.
So I can now hear people go "so what he is either stupid or nuts*, as they close this from there view and move on about their day, but let me say this, this is a HUGE problem, I seriously can’t stress that enough. This is what causes the problem with the server eventually timing out or the clients arbitrarily disconnecting for no reason.
Unity has utterly ignored the request time and time again to allow us control over the game loop, rather completely refused it, which is fine and your deal, but if you do this and have the Raknet wrapped around the game loop outside of our control, you MUST and I do mean absolutely MUST have a handle on that heartbeat, both for the client and the server. At this point though, you don’t. Seriously, there are zero network commands for us to send a periodic ping to the server, or to have the client send the server a heartbeat request, or for the server to control the general heartbeat.
I had sent in a ticket almost a week ago now with a project that uses Raknet as a .Net assembly, in that project is a client setup and a server setup within the core interface that uses the Heartbeat commands. In essence in the purest form of Raknet, this is the RakPeer Packet Receiver:
/// Gets a message from the incoming message queue.
/// Use DeallocatePacket() to deallocate the message after you are done with it.
/// User-thread functions, such as RPC calls and the plugin function PluginInterface::Update occur here.
/// \return 0 if no packets are waiting to be handled, otherwise a pointer to a packet.
/// \note COMMON MISTAKE: Be sure to call this in a loop, once per game tick, until it returns 0. If you only process one packet per game tick they will buffer up.
/// sa RakNetTypes.h contains struct Packet
virtual Packet* Receive( void )=0;
Which is the same as the Heartbeat in the .Net wrapper assembly. Please note the method definition, and pay very close attention to the “COMMON MISTAKE:” This is what is happening in Unity right now, the “COMMON MISTAKE”…
Since when focus to the Unity game is lost, the game is more or less in a sleep() state, guess what doesn’t get called? When the server is running and chugging along, and clients start to arbitrarly start to disconnect, what is not being called? This…
I saw this happening and I was like “OMG” no way… I am a complete bafoon and I ran across this. I am the most hyper individual on the planet, and cought this. People have been complaining of client disconnects and server issues since 2.1 and I bet you odds are this is the problem child. If the buffer of commands gets so far behind, the server will just puke, if the client looses focus and sleeps the network interface, it will drop from the server, if the server has anything that takes presidence and sleeps the unity thread to long, the server will barf and die.
This really has to be fixed by the next release.
Seriously.