How to avoid P2P disconnects every 40 seconds?

I’m using the NetworkTransport API for a turn-based game, in pretty much the same way as this tutorial explains: Good Enough Guide to Unity’s Unet Transport Layer (LLAPI) – Robot Monkey Brain

I have only two players, they successfully connect to each other by IP (not matchmaking), and successfully exchange messages every second or so.

However, every 40-50 seconds, the clients receive “Disconnect” messages, with the error number 6, aka “Timeout”. The disconnects don’t happen simultaneously on each client. Every time I restore the connection following the disconnect, but another disconnect comes 40-50 seconds after connection is established.

  • I tried to crank up all sorts of timeouts in the ConnectionConfig class, without effect. Also, none of the timeout values I checked correspond to 40-50 seconds
  • I tried clients on the same local network and different networks, without effect (except in the timeout value, which was exactly every 37-38 seconds on different networks, but was variable between 40-50 on LAN). It also happens when both clients are on the same computer.
  • I tried different channel types: Reliable (which is what I want), Unreliable, AllCostDelivery. It made no difference.
  • I looked up the forums, google, answers, but while others seem to have similar problems, no solution has been mentioned.

I don’t think I’m doing anything wrong, unexpected or special with my code. Pretty much basic peer to peer. Does anyone know if this is a bug with Unity, or if there’s a hidden setting that must be changed in order to make multiplayer work?

PS: I’m on Unity 5.3.3f1

I am having the same issue but with match making with NetworkManager.

My game is a multiplayer card game, so it does not send a lot of messages over the network (only when a card is placed) but there would be 30-seconds to 1 minute where the player is just thinking.

What I noticed is that if I leave the players in Idle state they get disconnected after about 40 to 50 seconds.

But if I send messages that disconnect gets postponed a bit, but that does not completely stop random disconnects.

I do not know the type of game you are making, but did you try sending a ping message between players every second or so?

I got an answer on the forum:

In my case increasing the network drop threshold mostly fixed the issue.