Skip to content

Commit

Permalink
fix: enable runInBackground so that connections dont timeout
Browse files Browse the repository at this point in the history
peer runs on main thread, so will be paused if runInBackground is false. This causes connections to timeout.

RunInBackground will be enabled by default but there is insecptor option to disable it if needed
  • Loading branch information
James-Frowen committed Jun 3, 2022
1 parent 567623a commit cb1b869
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Assets/Mirage/Runtime/NetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class NetworkClient : MonoBehaviour, INetworkClient

public bool DisconnectOnException = true;

[Tooltip("If true will set Application.runInBackground")]
public bool RunInBackground = true;

Peer peer;

[Tooltip("Authentication component attached to this object")]
Expand Down Expand Up @@ -132,6 +135,9 @@ public void Connect(string address = null, ushort? port = null)

IConnection connection = peer.Connect(endPoint);

if (RunInBackground)
Application.runInBackground = RunInBackground;

// setup all the handlers
Player = new NetworkPlayer(connection);
dataHandler.SetConnection(connection, Player);
Expand Down
6 changes: 6 additions & 0 deletions Assets/Mirage/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class NetworkServer : MonoBehaviour, INetworkServer

public bool DisconnectOnException = true;

[Tooltip("If true will set Application.runInBackground")]
public bool RunInBackground = true;

[Tooltip("If disabled the server will not create a Network Peer to listen. This can be used to run server single player mode")]
public bool Listening = true;

Expand Down Expand Up @@ -230,6 +233,9 @@ public void StartServer(NetworkClient localClient = null)
peer.Bind(SocketFactory.GetBindEndPoint());

if (logger.LogEnabled()) logger.Log($"Server started, listening for connections. Using socket {socket.GetType()}");

if (RunInBackground)
Application.runInBackground = RunInBackground;
}
else
{
Expand Down

0 comments on commit cb1b869

Please sign in to comment.