Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved Disconnected transport after sleeping

Discussion in 'Unity Transport' started by Farshadfarzan368, Apr 16, 2023.

  1. Farshadfarzan368

    Farshadfarzan368

    Joined:
    Sep 10, 2022
    Posts:
    65
    Hello, I made an online game for Android with transport, but when I don't use the phone for a while or when I go to rest mode, the connection is disconnected and the application stops working, what is the reason?
     
  2. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    384
    From the information you provided, it could be one of two things:
    1. The connection was closed due to inactivity. If we don't hear anything from the remote peer for a while, the connection gets closed. By default this is 30 seconds. Check this question in the FAQ about modifying this timeout. The next question also deals with finding the reason the connection was closed, which could be useful in confirming what the issue is.
    2. After a while, both iOS and Android will eventually free up the resources of a backgrounded app. This can include closing its sockets. Obviously once a socket is closed communications are not possible anymore. We have code in place to attempt to recreate UDP sockets, but if you're using WebSockets that won't work.