블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2375)N
Unity3D (592)N
Programming (473)
Unreal (4)
Gamebryo (56)
Tip & Tech (193)
협업 (37)
3DS Max (3)
Game (12)
Utility (118)
Etc (92)
Link (31)
Portfolio (19)
Subject (90)
iOS,OSX (38)
Android (13)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (1)
Memories (20)
Interest (37)
Thinking (37)
한글 (26)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (19)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total1,378,296
Today205
Yesterday428
Statistics Graph

달력

« » 2020.2
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29

공지사항

태그목록

'2020/02/07'에 해당되는 글 1건

  1. 2020.02.07 [펌] How to 100% check internet availability

Using this method you can see if you are able to view the page you wanted or not by accessing the html of that page you can read it to see if you got redirected or not. this example uses www.google.com as it's check

 

 using System.Net;
 public string GetHtmlFromUri(string resource)
 {
     string html = string.Empty;
     HttpWebRequest req = (HttpWebRequest)WebRequest.Create(resource);
     try
     {
         using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
         {
             bool isSuccess = (int)resp.StatusCode < 299 && (int)resp.StatusCode >= 200;
             if (isSuccess)
             {
                 using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
                 {
                     //We are limiting the array to 80 so we don't have
                     //to parse the entire html document feel free to 
                     //adjust (probably stay under 300)
                     char[] cs = new char[80];
                     reader.Read(cs, 0, cs.Length);
                     foreach(char ch in cs)
                     {
                         html +=ch;
                     }
                 }
             }
         }
     }
     catch
     {
         return "";
     }
     return html;
 }

 

This is to call the function

 using System.Net;
 void Start()
 {
     string HtmlText = GetHtmlFromUri("http://google.com");
     if(HtmlText == "")
     {
         //No connection
     }
     else if(!HtmlText.Contains("schema.org/WebPage"))
     {
         //Redirecting since the beginning of googles html contains that 
         //phrase and it was not found
     }
     else
     {
         //success
     }
 }

 

 

[출처] https://answers.unity.com/questions/567497/how-to-100-check-internet-availability.html

 

How to 100% check internet availability - Unity Answers

 

answers.unity.com

 

Posted by blueasa

댓글을 달아 주세요