Search Unity

UDP setup and teardown with application focus and application pause

Discussion in 'iOS and tvOS' started by epit, Apr 25, 2016.

  1. epit

    epit

    Joined:
    Oct 2, 2012
    Posts:
    32
    The app I am writing which uses custom UDP sockets works very well EXCEPT for extreme flakiness when the app is opened and closed and then re-opened.

    I'm trying to tear down the socket on ApplicationPause and re-initialize it on ApplicationFocus but seem to run into freezing and/or the app quitting sporadically.

    I know I am not doing something right, I just don't know what

    When the app comes into the Focus, I am doing

    IPEndPoint ipep = new IPEndPoint(IPAddress.Any, port);
    newsock= new UdpClient(ipep);

    receiveThread = new Thread(new ThreadStart(UDPReceiveData));
    receiveThread.IsBackground = true;
    receiveThread.Start();

    When the app is going to be Pause, I am doing

    if (receiveThread!=null)
    {
    receiveThread.Interrupt();
    }

    if (newsock!=null)
    {
    newsock.Close ();
    }

    Is my thinking correct..... should I being tearing down and re-setting-up like this. I know that IOS let's apps have a certain amount of time before shutting everything down when going into the background. Is perhaps this related to my freezing/quitting problem..... re-opening the app before all background tasks for fully shut down?

    Thanks in advance for any help....