Author Topic: OnApplicationPause connection lost (video sharing feature)  (Read 4590 times)

creativitysquare

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 2
  • Posts: 41
    • View Profile
OnApplicationPause connection lost (video sharing feature)
« on: November 24, 2014, 05:58:50 AM »
hi guys

I was wondering about the following. I am implementing Kamcord in my game and there is an issue with networking as if i record something and i watch and share it, when i go back to the game i got disconnected. I was thinking that maybe one way to prevent it would be to do something like:

  1. public bool paused;
  2.         void LateUpdate(){
  3.                 if (paused) {
  4.                         System.Net.IPEndPoint ip = new System.Net.IPEndPoint(NUtils.SERVER_ADDRESS, NUtils.SERVER_PORT);
  5.                         TNManager.Ping (ip, OnPing ());
  6.                 }
  7.         }
  8.         void OnApplicationPause(bool pauseStatus) {
  9.                 paused = pauseStatus;
  10.         }
  11.         void OnPing(){
  12.                 Debug.Log ("keep alive");
  13.         }
  14.  
  15. or
  16.  
  17. void OnApplicationPause(bool pauseStatus) {
  18.                
  19.      StartCoroutine (KeepConAlive());
  20.                
  21. }
  22.  
  23. IEnumerator KeepConAlive (){
  24.                 for ( ; ; )
  25.                 {
  26.                         if (TNManager.isInChannel)
  27.                         {
  28.                                 if (TNManager.isThisMyObject) {
  29.                                         System.Net.IPAddress ipAd = new               System.Net.IPAddress(System.Convert.ToInt64(NUtils.SERVER_ADDRESS));
  30.                                         System.Net.IPEndPoint ip = new System.Net.IPEndPoint(ipAd, NUtils.SERVER_PORT);
  31.                                         TNManager.Ping (ip,null);
  32.                                 }
  33.                                 yield return new WaitForSeconds(1f);
  34.                         }
  35.                         else yield return new WaitForSeconds(0.1f);
  36.                 }
  37. }
  38.  

This approach doesn't work. Any idea how can i keep the con alive?

Many thanks
CS
« Last Edit: November 24, 2014, 06:53:45 AM by creativitysquare »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnApplicationPause connection lost (video sharing feature)
« Reply #1 on: November 25, 2014, 02:01:19 AM »
When the app is paused, no more updates go through. No more updates = no packets, so the connection is believed to be dead, resulting in a disconnect. You can get around it by setting the TNManager.SetTimeout to a high value.

creativitysquare

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 2
  • Posts: 41
    • View Profile
Re: OnApplicationPause connection lost (video sharing feature)
« Reply #2 on: December 05, 2014, 09:32:12 PM »
thanks Aren
I will try this

creativitysquare

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 2
  • Posts: 41
    • View Profile
Re: OnApplicationPause connection lost (video sharing feature)
« Reply #3 on: December 06, 2014, 08:06:52 AM »
It works perfectly

  1.  /// <summary>
  2.     /// Raises the application pause event.
  3.     /// </summary>
  4.     /// <param name="pauseStatus">If set to <c>true</c> pause status.</param>
  5.     void OnApplicationPause(bool pauseStatus){
  6.         if(pauseStatus){
  7.             if(TNManager.isConnected) TNManager.SetTimeout(180);Debug.Log ("APP PAUSED " + pauseStatus);
  8.         }else{
  9.             if(TNManager.isConnected) TNManager.SetTimeout(10);Debug.Log ("APP UNPAUSED " + pauseStatus);
  10.         }
  11.     }

thanks again