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.

Bug SocketException: mono-io-layer-error (111) error in south korea

Discussion in 'Editor & General Support' started by PhobosRandom, Jun 13, 2023.

  1. PhobosRandom

    PhobosRandom

    Joined:
    May 13, 2020
    Posts:
    20
    In the first scene launched in our mobile game we gather information about the location of the player, and then once done, we launch the game.
    But a friend in south korea is stuck on this intro page and receive this error :

    Code (CSharp):
    1. SocketException: mono-io-layer-error (111)
    2. System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () (at <00000000000000000000000000000000>:0)
    3. System.Action`1[T].Invoke (T obj) (at <00000000000000000000000000000000>:0)
    4. System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) (at <00000000000000000000000000000000>:0)
    5. System.AsyncCallback.Invoke (System.IAsyncResult ar) (at <00000000000000000000000000000000>:0)
    6. System.Threading.WaitCallback.Invoke (System.Object state) (at <00000000000000000000000000000000>:0)
    7. System.Threading.ThreadPoolWorkQueue.Dispatch () (at <00000000000000000000000000000000>:0)
    8. --- End of stack trace from previous location where exception was thrown ---
    9. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <00000000000000000000000000000000>:0)
    10. System.Net.WebConnection+<Connect>d__16.MoveNext () (at <00000000000000000000000000000000>:0)
    11. System.Threading.ContextCallback.Invoke (System.Object state) (at <00000000000000000000000000000000>:0)
    12. System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <00000000000000000000000000000000>:0)
    13. System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () (at <00000000000000000000000000000000>:0)
    14. System.Action.Invoke () (at <00000000000000000000000000000000>:0)
    15. System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) (at <00000000000000000000000000000000>:0)
    16. System.Threading.Tasks.Task.FinishContinuations () (at <00000000000000000000000000000000>:0)
    17. System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) (at <00000000000000000000000000000000>:0)
    18. System.Threading.Tasks.Task`1[TResult].TrySetException (System.Object exceptionObject) (at <00000000000000000000000000000000>:0)
    19. System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) (at <00000000000000000000000000000000>:0)
    20. System.AsyncCallback.Invoke (System.IAsyncResult ar) (at <00000000000000000000000000000000>:0)
    21. System.Threading.WaitCallback.Invoke (System.Object state) (at <00000000000000000000000000000000>:0)
    22. System.Threading.ThreadPoolWorkQueue.Dispatch () (at <00000000000000000000000000000000>:0)
    23. Rethrow as WebException: Error: ConnectFailure (mono-io-layer-error (111))
    24. System.Net.WebConnection+<Connect>d__16.MoveNext () (at <00000000000000000000000000000000>:0)
    25. System.Threading.ContextCallback.Invoke (System.Object state) (at <00000000000000000000000000000000>:0)
    26. System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <00000000000000000000000000000000>:0)
    27. System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () (at <00000000000000000000000000000000>:0)
    28. System.Action.Invoke () (at <00000000000000000000000000000000>:0)
    29. System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) (at <00000000000000000000000000000000>:0)
    30. System.Threading.Tasks.Task.FinishContinuations () (at <00000000000000000000000000000000>:0)
    31. System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) (at <00000000000000000000000000000000>:0)
    32. System.Threading.Tasks.Task`1[TResult].TrySetException (System.Object exceptionObject) (at <00000000000000000000000000000000>:0)
    33. System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) (at <00000000000000000000000000000000>:0)
    34. System.AsyncCallback.Invoke (System.IAsyncResult ar) (at <00000000000000000000000000000000>:0)
    35. System.Threading.WaitCallback.Invoke (System.Object state) (at <00000000000000000000000000000000>:0)
    36. System.Threading.ThreadPoolWorkQueue.Dispatch () (at <00000000000000000000000000000000>:0)
    37. --- End of stack trace from previous location where exception was thrown ---
    38. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <00000000000000000000000000000000>:0)
    39. System.Net.WebConnection+<InitConnection>d__19.MoveNext () (at <00000000000000000000000000000000>:0)
    40. System.Threading.ContextCallback.Invoke (System.Object state) (at <00000000000000000000000000000000>:0)
    41. System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <00000000000000000000000000000000>:0)
    42. System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () (at <00000000000000000000000000000000>:0)
    43. System.Action.Invoke () (at <00000000000000000000000000000000>:0)
    44. System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) (at <00000000000000000000000000000000>:0)
    45. System.Threading.Tasks.Task.FinishContinuations () (at <00000000000000000000000000000000>:0)
    46. System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) (at <00000000000000000000000000000000>:0)
    47. System.Threading.Tasks.Task`1[TResult].TrySetException (System.Object exceptionObject) (at <00000000000000000000000000000000>:0)
    48. System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].SetException (System.Exception exception) (at <00000000000000000000000000000000>:0)
    49. System.Net.WebConnection+<Connect>d__16.MoveNext () (at <00000000000000000000000000000000>:0)
    50. System.Threading.ContextCallback.Invoke (System.Object state) (at <00000000000000000000000000000000>:0)
    51. System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <00000000000000000000000000000000>:0)
    52. System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () (at <00000000000000000000000000000000>:0)
    53. System.Action.Invoke () (at <00000000000000000000000000000000>:0)
    54. System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) (at <00000000000000000000000000000000>:0)
    55. System.Threading.Tasks.Task.FinishContinuations () (at <00000000000000000000000000000000>:0)
    56. System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) (at <00000000000000000000000000000000>:0)
    57. System.Threading.Tasks.Task`1[TResult].TrySetException (System.Object exceptionObject) (at <00000000000000000000000000000000>:0)
    58. System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) (at <00000000000000000000000000000000>:0)
    59. System.AsyncCallback.Invoke (System.IAsyncResult ar) (at <00000000000000000000000000000000>:0)
    60. System.Threading.WaitCallback.Invoke (System.Object state) (at <00000000000000000000000000000000>:0)
    61. System.Threading.ThreadPoolWorkQueue.Dispatch () (at <00000000000000000000000000000000>:0)
    62. --- End of stack trace from previous location where exception was thrown ---
    63. System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <00000000000000000000000000000000>:0)
    64. System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () (at <00000000000000000000000000000000>:0)
    65. System.Net.WebOperation+<Run>d__54.MoveNext () (at <00000000000000000000000000000000>:0)
    66. System.Threading.ContextCallback.Invoke (System.Object state) (at <00000000000000000000000000000000>:0)
    67. System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <00000000000000000000000000000000>:0)
    68. System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () (at <00000000000000000000000000000000>:0)
    69. System.Action.Invoke () (at <00000000000000000000000000000000>:0)
    70. System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action action, System.Boolean allowInlining, System.Threading.Tasks.Task& currentTask) (at <00000000000000000000000000000000>:0)
    71. System.Threading.Tasks.Task.FinishContinuations () (at <00000000000000000000000000000000>:0)
    72. System.Threading.Tasks.Task.Finish (System.Boolean bUserDelegateExecuted) (at <00000000000000000000000000000000>:0)
    73. System.Threading.Tasks.Task`1[TResult].TrySetException (System.Object exceptionObject) (at <00000000000000000000000000000000>:0)
    74. System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].SetException (System.Exception exception) (at <00000000000000000000000000000000>:0)
    75. System.Net.WebConnection+<InitConnection>d__19.MoveNext () (at <00000000000000000000000000000000>:0)
    76. System.Threading.ContextCallback.Invoke (System.Object state) (at <00000000000000000000000000000000>:0)
    77. System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <00000000000000000000000000000000>:0)
    78. System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () (at <00000000000000000000000000000000>:0)
    79. System.Action.Invoke () <truncated>
    I don't know from where it's comming and I can't manage to reproduce the bug. I tried setting my ip to south korea, but for me everything is working correctly.

    Here is the code we use in the intro scene, I think it comes from the function GetUserCountryByIp, but I can't manage to find why.


    Code (CSharp):
    1. public class Intro : MonoBehaviour
    2. {
    3.     public GameObject phonePanel, codePanel, askPanel;
    4.     public Button sendPhone, resendPhone, sendCode;
    5.     public TMPro.TMP_InputField phoneNumberInput, codeInput;
    6.     public TMPro.TMP_Text invalidNumber, codeIncorrect, countryCode;
    7.     [HideInInspector]
    8.     public string phoneNumber;
    9.     public string code;
    10.  
    11.     // Start is called before the first frame update
    12.     void Start()
    13.     {
    14.         initOneSignal();
    15.         phoneNumberInput.keyboardType = TouchScreenKeyboardType.PhonePad;
    16.         codeInput.keyboardType = TouchScreenKeyboardType.PhonePad;
    17.  
    18.         if (PlayerPrefs.HasKey("isAfrican"))
    19.         {
    20.             StartCoroutine(loadMainMenu());
    21.  
    22.         }else
    23.         {
    24.             StartCoroutine(GetUserCountryByIp());
    25.         }
    26.     }
    27.  
    28.     /// <summary>
    29.     /// Load the menu after waiting for 2 seconds
    30.     /// </summary>
    31.     /// <returns></returns>
    32.     public IEnumerator loadMainMenu()
    33.     {
    34.         yield return new WaitForSeconds(3);
    35.         ScenesLoadHendeler.current.LoadMainMenu();
    36.     }
    37.  
    38.     /// <summary>
    39.     /// Get the user country by ip
    40.     /// </summary>
    41.     /// <returns></returns>
    42.     public static IEnumerator GetUserCountryByIp()
    43.     {
    44.         string ip = new System.Net.WebClient().DownloadString("https://api.ipify.org");
    45.         //ip = "102.164.128.0";
    46.         //ip = "103.117.0.0";
    47.         //ip = "1.16.63.255";
    48.         Debug.Log("found IP : " + ip);
    49.         string uri = $"https://ipapi.co/{ip}/json/?key=5DtkttZilefNF2eSeJq9stTnjKydxmBTq636dBZVTZvfg3t0dr";
    50.  
    51.  
    52.         using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
    53.         {
    54.             yield return webRequest.SendWebRequest();
    55.  
    56.             string[] pages = uri.Split('/');
    57.             int page = pages.Length - 1;
    58.             Debug.Log(webRequest.downloadHandler.text);
    59.             IpApiData ipApiData = IpApiData.CreateFromJSON(webRequest.downloadHandler.text);
    60.  
    61.             Debug.Log(ipApiData.country_code);
    62.             PlayerPrefs.SetString("countryCode", ipApiData.country_code);
    63.             // We send the data to the back end
    64.             RestClient.Get(PlayerService.rootApi + PlayerService.playerApi + "isAfricanUser?countryCode=" + ipApiData.country_code).Then(response => {
    65.  
    66.                 Debug.Log(response.Text);
    67.                 Debug.Log(response.StatusCode);
    68.                 if (response.StatusCode == 200)
    69.                 {
    70.                     bool isAfricanCountry = bool.Parse(response.Text);
    71.                     if (!isAfricanCountry)
    72.                         PlayerPrefs.SetInt("isAfrican", /*1*/0);
    73.                     else
    74.                         PlayerPrefs.SetInt("isAfrican", 1);
    75.  
    76.                     new WaitForSeconds(3);
    77.                     ScenesLoadHendeler.current.LoadMainMenu();
    78.                 }
    79.                 else
    80.                 {
    81.                     // alert message
    82.                     //Error during the process
    83.                 }
    84.  
    85.             });
    86.         }
    87.     }
    88.  
    89.     void initOneSignal()
    90.     {
    91.         // Uncomment this method to enable OneSignal Debugging log output
    92.         // OneSignal.SetLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
    93.  
    94.         // Replace 'YOUR_ONESIGNAL_APP_ID' with your OneSignal App ID.
    95.         OneSignal.StartInit("dc8f7098-8231-418d-b5e6-82c3498f7463")
    96.           .HandleNotificationOpened(OneSignalHandleNotificationOpened)
    97.           .Settings(new Dictionary<string, bool>() {
    98.       { OneSignal.kOSSettingsAutoPrompt, false },
    99.       { OneSignal.kOSSettingsInAppLaunchURL, false } })
    100.           .EndInit();
    101.  
    102.         OneSignal.inFocusDisplayType = OneSignal.OSInFocusDisplayOption.Notification;
    103.  
    104.         // iOS - Shows the iOS native notification permission prompt.
    105.         //   - Instead we recomemnd using an In-App Message to prompt for notification
    106.         //     permission to explain how notifications are helpful to your users.
    107.         OneSignal.PromptForPushNotificationsWithUserResponse(OneSignalPromptForPushNotificationsReponse);
    108.     }
    109.  
    110.     // Gets called when the player opens a OneSignal notification.
    111.     private static void OneSignalHandleNotificationOpened(OSNotificationOpenedResult result)
    112.     {
    113.         // Place your app specific notification opened logic here.
    114.     }
    115.  
    116.     // iOS - Fires when the user anwser the notification permission prompt.
    117.     private void OneSignalPromptForPushNotificationsReponse(bool accepted)
    118.     {
    119.         // Optional callback if you need to know when the user accepts or declines notification permissions.
    120.     }
    121.  
    122.  
    123.     public IEnumerator LoadMenu()
    124.     {
    125.         float timerStart = Time.time;
    126.         bool waiting = true;
    127.         while (waiting)
    128.         {
    129.             waiting = Time.time < timerStart + 5;
    130.             if (Input.GetMouseButton(0))
    131.             {
    132.                 Debug.Log("Skipping");
    133.                 waiting = false;
    134.             }
    135.             yield return new WaitForEndOfFrame();
    136.         }
    137.         ScenesLoadHendeler.current.LoadMainMenu();
    138.         yield return null;
    139.     }
    140. }
    141.  
    142. [Serializable]
    143. public class CountryInformation
    144. {
    145.     public string code;
    146.     public string name;
    147.     public string flagUrl;
    148.     public bool isAfricanCountry;
    149. }
    150.  
    151. [Serializable]
    152. public class IpApiData
    153. {
    154.     public string country_name;
    155.     public string country_code;
    156.     public static IpApiData CreateFromJSON(string jsonString)
    157.     {
    158.         return JsonUtility.FromJson<IpApiData>(jsonString);
    159.     }
    160. }
    Thank you
     
    Last edited: Jun 13, 2023