본문 바로가기
개발/Unity

Unity) Network Connection Check(인터넷 연결 확인 / Wi-fi 연결 )

by 테샤르 2022. 8. 31.

Network Connection Check(인터넷 연결 확인 /  Wi-fi 연결 )

 

Unity 에서 제공하는 internetReachability값을 활용해서 간단하게 체크가 가능하다.

옵션으로는 다음과 같다.

속성 설명
NotReachable 연결불가
ReachableViaCarrierDataNetwork 셀룰러연결 (이동 통신사 네트워크)
ReachableViaLocalAreaNetwork Wi-Fi 연결

 

//Attach this script to a GameObject
//This script checks the device’s ability to reach the internet and outputs it to the console window

using UnityEngine;

public class Example : MonoBehaviour
{
    string m_ReachabilityText;

    void Update()
    {
//Output the network reachability to the console window
        Debug.Log("Internet : " + m_ReachabilityText);
        //Check if the device cannot reach the internet
        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            //Change the Text
            m_ReachabilityText = "Not Reachable.";
        }
        //Check if the device can reach the internet via a carrier data network
        else if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
        {
            m_ReachabilityText = "Reachable via carrier data network.";
        }
        //Check if the device can reach the internet via a LAN
        else if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
        {
            m_ReachabilityText = "Reachable via Local Area Network.";
        }
    }
}

 

반응형

 

해당정보가 정확하지 않는경우에는 Network 연결을 통해서 Ping 의 여부 체크 혹은

실제 WWW 호출 이후의 커넥션확인 등 여러가지 추가 방안으로 처리를 해야한다.

위의 internetReachability 정보는 네트워크 연결의 여부가 아닌 어디에 연결됬는지를 판단하기 때문이다.

 

Unity Application.internetReachability : [링크]

 

Unity - Scripting API: NetworkReachability

Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close

docs.unity3d.com

Checking internet connection at runtime in Unity : [링크]

 

Checking internet connection at runtime in Unity

How can I check internet connection inside Update Function in unity? I want to know whether the user is connected or not, and based on that just disable some functionality of my game. Seems like t...

stackoverflow.com

How to check internet connection in an app : [링크]

 

How to check internet connection in an app

Hello all. I just a newbie in the programming Unity. And I here have a trouble. I have an app, and I want this app when running in Android/iOS...

forum.unity.com

 

★☆☆☆☆

 

반응형

댓글