• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by paulsz · Nov 29, 2010 at 02:29 PM · connectioncheck

How can one test if there is any internet (wi-fi or ethernet) connection available ?

My current game deals with all cases when an internet connection is available but does not deal with the case when there is no internet connection, resulting in nasty errors of course which should be dealt with before they occur by testing if the Network operations can be performed in the first place.

When trying to run the test the connection with the example from the reference guide, if no internet connection is present, this error occurs:

"Cannot resolve connection tester address, you must be connected to the internet before performing this or set the address to something accessible to you."

To completely cover all the cases, I need to allways know if there is an internet connection. Polling the network connection with the function Network.TestConnection() does not work at all and does not address my issue since it refers mainly to NAT punchthrough statuses.

Thanks in advance for any help out there :)

Comment
cregox

People who like this

1 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

  • Sort: 
avatar image
Best Answer

Answer by paulsz · Dec 13, 2010 at 06:12 PM

I have posted the same issue on the forums and iceshaft07 kindly shared his solution with me:

http://forum.unity3d.com/threads/68938-How-can-you-tell-if-there-exists-a-network-connection-of-any-kind

Thx alot guys

Cheers to iceshaft07 :D

Comment
flamy
taxvi
isaialv
mollermanden

People who like this

4 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cregox · Nov 06, 2012 at 03:55 PM 0
Share

I prefer this solution: http://answers.unity3d.com/answers/343863/view.html

avatar image taxvi · Jan 15, 2015 at 02:39 PM 0
Share

cheers to iceshaft07! :D

avatar image

Answer by Tuor · Oct 19, 2011 at 07:20 PM

Look for Application.internetReachability in the scripting api.

Comment
$$anonymous$$
Hola Soy Edu Feliz Navidad
tituszban
illustir
ApenasVB

People who like this

5 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by Loius · Nov 29, 2010 at 03:25 PM

Does a try-catch block help?

try {
 Connect();
} catch ( e ) {
 Debug.Log( "Connect error: " + e.message);
}

Comment

People who like this

0 Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image paulsz · Nov 29, 2010 at 03:55 PM 0
Share

Sadly this does not help :( I already tried this approach but the fact of the matter is that the error is triggered within unity engine long after (a few seconds even) the Network.Connect() method is called since connection is not done immediately as the function is called.

I'm sure the solution should be like a polling system (the same as used when looking for hosts ) which checks every frame if there is internet connection. It surprises me that I have not found a single thread about this problem on the forums or on the answers since this is a pretty big deal. Thank you for your response :)

avatar image Loius · Nov 30, 2010 at 03:40 AM 0
Share

You might try "yield Network.Connect();", if .Connect is a 'real' coroutine that should wait for it to finish and maybe the error will be reportable? Unfortunately I haven't worked at all with internetness; hopefully someone else will come in here and know something at you!

avatar image paulsz · Dec 08, 2010 at 12:27 PM 0
Share

Thx for the answer Vicenti,

It would have been awesome to be able to do it like you said but you cannot put a yield statement in a try catch block-> try { yield return Network.Connect( "address" ); } catch ( System.Exception aException ) { }

gives the compilation error: "error CS1626: Cannot yield a value in the body of a try block with a catch clause".

Anyway, I think I might have figured it out in a not very elegant manner: Just check every frame if there is Wifi with iPhoneSettings.internetReachability. Unfortunately this only works on the iphone

avatar image

Answer by tonic · Jul 06, 2014 at 01:05 PM

(Adding a comment to an old posting in case somebody finds this using search...)

To truly know you're online, you need to implement "captive portal detection", to know if you're e.g. hitting a public WiFi login page. So just checking Application.internetReachability or doing a Ping to some address doesn't guarantee you can successfully make connections or make WWW requests.

I have made an easy asset called Internet Reachability Verifier. It keeps you up-to-date whether you have verified internet access (WWW requests can be done). Works with Desktop, Mobile and Webplayer platforms (need to self-host a file in originating server for Webplayer).

More info here: http://j.mp/IRVUN

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by grujicbr · Aug 19, 2014 at 09:55 PM

Hi,

I have released a event based plugin for ios that lets you do exactly this without having to do it manually. It is very easy to use and works on all ios devices. Android version is on works as well

https://www.assetstore.unity3d.com/en/#!/content/19869

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to check iphone network connection 0 Answers

Connecting to server through IP. ? tutorial thats not local trash? 0 Answers

Networking problems 2 Answers

yield return WWW stops Coroutine? 0 Answers

What is the difference between Social.localUser and Social.Active.localUser? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges