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.

[RELEASED] SolarWind Connectivity - Cross-Platform, reliable, Internet detection!

Discussion in 'Assets and Asset Store' started by dimitriosb, Sep 12, 2016.

  1. dimitriosb

    dimitriosb

    Joined:
    May 5, 2014
    Posts:
    17


    Hello, everyone!

    SolarWind Connectivity is now available in the Unity Asset Store!

    We (at Total Eclipse) have been working on this for quite some time, as it has been an integral part of a released multi-platform product (our puzzle game, A Clockwork Brain).

    In short, with SolarWind Connectivity you can always know whether you really are connected to the Internet, under any circumstances. Please read below for more information. I hope that you will find it as useful as we did. I'll be really happy to answer any questions you might have, or hear your comments!

    Dimitrios
    Co-Founder & CTO

    ---

    LINKS

    - Supports Unity 5 (any edition) / Unity 4.7.2+ Free/Pro
    - Multi-platform support (Android, iOS (IL2CPP), Windows Store 8.1/10 X86/ARM, PC & Mac Standalone)
    - Comes with full source code


    ABOUT SOLARWIND CONNECTIVITY

    SolarWind Connectivity is a flexible and powerful Unity Plugin for detecting the actual Internet connectivity on any device and platform, as Unity's Application.internetReachability cannot always be relied upon. Desktop devices are always considered as connected via LAN, and Portable devices can appear as connected but not have broad access to the Internet. This is what SolarWind Connectivity is about: a surefire way of always knowing whether you really are connected to the Internet, under any circumstances.

    In some cases generic Internet detections is not enough, e.g. the app might need to know if it can connect to a specific backend service. The plugin can also detect the connectivity of different destinations at the same time, and provides a convenient API for that. It also allows you to register as many different detectors as you want in order to suit your project's needs. Lastly, it is extremely flexible and extensible as you can configure detectors to be invoked on demand or have them automatically perform a detection periodically.

    FEATURES
    • Reliable detection of Internet connectivity at all times
    • Multi-platform support: Android, iOS, Windows Store X86/ARM, PC & Mac Standalone
    • Ready to use detectors: Google 204 page, Microsoft NCSI, Apple hotspot & success pages
    • Detectors that point to custom URLs
    • Two different detection methods: HTTP status code or by response string, easily extensible
    • Recurring detection or ultra-lightweight manual detection
    • Information about connectivity changes: total time connected/disconnected, latest detection time, connection history, errors, etc
    • High extensibility, for suiting custom needs
    EASE OF USE
    Using the plugin is very easy and can be done with a few lines of code. All you need do is call an initialization method, register a detector and then start querying the network status.
    Code (csharp):
    1. void Start() {
    2.   UnityReachability.Init();
    3.   IConnectivityDetector detector = DetectorFactory.CreateGoogle204Detector();
    4.   DetectorLocator.Instance.AddGenericDetector(detector);
    5. }
    6.  
    7. void Update() {
    8.   bool active = DetectorLocator.Instance.GetGenericDetector().IsConnectionActive();
    9.   Debug.Log("Connected: " + active);
    10. }
    A sample scene is also provided so that you can run your tests and see how the API is used. (Unity 4 & 5)



    View on the Asset Store
     
    Last edited: Sep 23, 2016
  2. stavrosk

    stavrosk

    Joined:
    Sep 14, 2016
    Posts:
    2
    Great plugin! Can you give me a bit of information about how detection is done? How does it decide it's connected to a service? How much bandwidth does it consume?

    Also, will it get fooled if, say, google.com gets redirected to a captive portal?
     
  3. dimitriosb

    dimitriosb

    Joined:
    May 5, 2014
    Posts:
    17
    Thanks stavrosk!

    The detectors make a web request to a predefined or custom url. The predefined urls are the same ones used by Google, Microsoft or Apple for detecting internet connectivity in Android, Windows and iOS/Mac devices. They are very light pages, up to 200 bytes each.

    The response is validated using either the HTTP status code (e.g. 204 for http://clients3.google.com/generate_204) or the response string (e.g. "Microsoft NCSI" in http://www.msftncsi.com/ncsi.txt). Matching part of the response string is also supported.

    If you are using a custom url, such as your backend server, you can choose the validation method that matches what your server returns. The bandwidth in this cases also depends on the response of your server.

    The detection only succeeds if the web server is really reached. In case the request is redirected to a captive portal, the connection will be considered to be inactive.
     
  4. stavrosk

    stavrosk

    Joined:
    Sep 14, 2016
    Posts:
    2
    Ah, sounds ideal, thank you! Especially since it won't be fooled by captive portals, which is something I've been bitten by previously.
     
    Argiris likes this.
  5. dimitriosb

    dimitriosb

    Joined:
    May 5, 2014
    Posts:
    17
    Update: There is now a demo video available, that shows how the plugin detects changes of connectivity:
     
  6. ibps13

    ibps13

    Joined:
    Oct 6, 2012
    Posts:
    113
    Hi,
    Just purshased and tested advanced example but I have some error:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. ConnectionBasedExecutor..ctor (IBroadcastingDetector _detector, System.Action _onSuccess, System.Action _onFailure) (at Assets/_RAVR_V1/Scripts/Utils/ConnectionBasedExecutor.cs:31)
    3. Ravr.RavrEarthInit.NetworkConnectionTest () (at Assets/_RAVR_V1/Scripts/RavrEarthInit.cs:116)
    4. Ravr.RavrEarthInit.OnEnable () (at Assets/_RAVR_V1/Scripts/RavrEarthInit.cs:83)
    used :

    Code (CSharp):
    1.  public void NetworkConnectionTest()
    2.         {
    3.             var executor = new ConnectionBasedExecutor(
    4.                 DetectorLocator.Instance.GetGenericDetector(),
    5.                 OnActiveConnection,
    6.                 OnNoConnection
    7.             );
    8.             executor.Execute();
    9.         }
    10.  
    11.         private void OnActiveConnection()
    12.         {
    13.             // There is an active connection
    14.             isConnectToInternet = true;
    15.         }
    16.  
    17.         private void OnNoConnection()
    18.         {
    19.             // There is no connection, display a message to the user
    20.             isConnectToInternet = false;
    21.         }
    With this class :

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3.  
    4. using UnityEngine;
    5.  
    6. using SolarWind.Collections;
    7. using SolarWind.Events;
    8. using SolarWind.Logging;
    9. using SolarWind.Network.Connectivity;
    10. using SolarWind.Network.Connectivity.Events;
    11. using SolarWind.Utils;
    12. using SolarWind.Unity.Network.Connectivity;
    13. /**
    14. * Executes an action, after first performing a manual detection of the Internet connectivity.
    15. * If there is no connection, it executes another action instead.
    16. */
    17. public class ConnectionBasedExecutor : IEventReceiver
    18. {
    19.  
    20.     private IBroadcastingDetector m_detector;
    21.     private Action m_onSuccess;
    22.     private Action m_onFailure;
    23.  
    24.     public ConnectionBasedExecutor(IBroadcastingDetector _detector, Action _onSuccess, Action _onFailure)
    25.     {
    26.         m_detector = _detector;
    27.         m_onSuccess = _onSuccess;
    28.         m_onFailure = _onFailure;
    29.  
    30.         // We add  a listener to that detector, in order to get notified of the detection result.
    31.         m_detector.AddListener(this);
    32.     }
    33.  
    34.     /**
    35.      * Initiates the detection, in order to execute the business logic.
    36.      */
    37.     public void Execute()
    38.     {
    39.         m_detector.DetectNow();
    40.     }
    41.  
    42.     /**
    43.      * Frees up resources.
    44.      */
    45.     private void Cleanup()
    46.     {
    47.         m_detector.RemoveListener(this);
    48.     }
    49.  
    50.     private void HandleConnectivityResult(ConnectivityResult _event)
    51.     {
    52.         if (_event.ConnectionResultType == ConnectionResultType.StableStatusChanged)
    53.         {
    54.             Cleanup();
    55.             if (_event.ConnectionActive)
    56.             {
    57.                 m_onSuccess();
    58.             }
    59.             else {
    60.                 m_onFailure();
    61.             }
    62.         }
    63.     }
    64.  
    65.     public void notify(SolarWind.Events.Event _event)
    66.     {
    67.         if (_event.type == ConnectivityResult.EVENT_ID)
    68.         {
    69.             HandleConnectivityResult(_event as ConnectivityResult);
    70.         }
    71.     }
    72. }
    73.  
    Thanks
     
  7. dimitriosb

    dimitriosb

    Joined:
    May 5, 2014
    Posts:
    17
    Hi @ibps13.

    I don't know if have included 100% of the code you are using, but from the code above it seems that you are missing two lines that are neccessary, in order to make this work:

    Code (csharp):
    1. UnityConnectivity.Init();
    2. DetectorLocator.Instance.AddGenericDetector(DetectorFactory.CreateGoogleDetector());
    The first line is necessary for the plugin to work, as it performs some internal initializations.

    The second line creates and registers a detector to the convenience locator class (DetectorLocator). If you don't register anything, then the following call will return null:
    Code (csharp):
    1. DetectorLocator.Instance.GetGenericDetector()
    Both of these lines must be executed before you create the ConnectionBasedExecutor instance.

    I just checked our docs and we are mentioning this in the Basic API section, but *we do not repeat that* in the Advanced API section. I understand that this can be confusing and error-prone, especially for anyone who refers to the Advanced section directly. I'll make sure we write this in a more clear way. Thank you for bringing this to our attention!

    If you are still having trouble, please tell me. You can always write to our support as well, we'll be happy to help!

    Dimitrios
     
  8. ibps13

    ibps13

    Joined:
    Oct 6, 2012
    Posts:
    113
    Hi @dimitriosb
    Yop, tried basic example and found this two line...
    Works fine indeed !! Thanks :)
     
  9. dimitriosb

    dimitriosb

    Joined:
    May 5, 2014
    Posts:
    17
    Great! Glad I could help, @ibps13!
     
unityunity