コード例 #1
0
    async void Start()
    {
        CarrierInfo carrierInfo = new TestCarrierInfoClass();
        DeviceInfo  deviceInfo  = new DeviceInfoIntegration(carrierInfo);

        mxi      = new MobiledgeXIntegration(carrierInfo: carrierInfo, deviceInfo: deviceInfo);
        location = await MobiledgeXIntegration.GetLocationFromIP();

        mxi.SetFallbackLocation(location.longitude, location.latitude);
        mxi.useFallbackLocation = true;
        try
        {
            await mxi.RegisterAndFindCloudlet();
        }
        //FindCloudletException is thrown if there is no app instance in the user region
        catch (FindCloudletException fce)
        {
            Debug.Log("FindCloudletException: " + fce.Message + "Inner Exception: " + fce.InnerException);
            // your fallback logic here
        }
        mxi.GetAppPort(LProto.L_PROTO_TCP); // or LProto.L_PROTO_UDP
        string url = mxi.GetUrl("http");    // or another L7 proto such as https, ws, wss, udp

        Debug.Log("url : " + url);          // Once you have your edge server url you can start communicating with your Edge server
    }
コード例 #2
0
    async void GetEdgeConnection()
    {
        mxi = new MobiledgeXIntegration();
        try
        {
            await mxi.RegisterAndFindCloudlet();
        }
        //RegisterClientException is thrown if your app is not found or if you carrier is not registered on MobiledgeX yet
        catch (RegisterClientException rce)
        {
            Debug.Log("RegisterClientException: " + rce.Message + "Inner Exception: " + rce.InnerException);
            mxi.UseWifiOnly(true); // use location only to find the app instance
            await mxi.RegisterAndFindCloudlet();
        }
        //FindCloudletException is thrown if there is no app instance in the user region
        catch (FindCloudletException fce)
        {
            Debug.Log("FindCloudletException: " + fce.Message + "Inner Exception: " + fce.InnerException);
            // your fallback logic here
        }
        // LocationException is thrown if the app user rejected location permission
        catch (LocationException locException)
        {
            print("Location Exception: " + locException.Message);
            mxi.useFallbackLocation = true;
            mxi.SetFallbackLocation(-122.4194, 37.7749); //Example only (SF location),In Production you can optionally use:  MobiledgeXIntegration.LocationFromIPAddress location = await MobiledgeXIntegration.GetLocationFromIP();
            await mxi.RegisterAndFindCloudlet();
        }
        mxi.GetAppPort(LProto.L_PROTO_TCP); // or LProto.L_PROTO_UDP
        string url = mxi.GetUrl("http");    // or another L7 proto such as https, ws, wss, udp

        Debug.Log("url : " + url);          // Once you have your edge server url you can start communicating with your Edge server deployed on MobiledgeX Console
        StartCoroutine(RestExample(url));   //using UnityWebRequest
        //await RestExampleHttpClient(url); // You can instead use HttpClient
    }
コード例 #3
0
        public CompanionDevice()
        {
            httpClient = new HttpClient();
            if (httpClient == null)
            {
                throw new Exception("Could not create an HTTP client!");
            }
            httpClient.Timeout = TimeSpan.FromTicks(DEFAULT_REST_TIMEOUT_MS * TICKS_PER_MS);

            NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
            // The Network Interface name should point to whichever one the default network route points to.
            // This just prints the complete list so a developer can create a new interface profile that is
            // unknown to the MobiledgeX Unity SDK.
            foreach (NetworkInterface adapter in interfaces)
            {
                Logger.D("XXXXXXX Interface Name: {0}", adapter.Name);
            }

            // Override network interface to support FindCloudlet interface checks.
            Mxi = new MobiledgeXIntegration(
                netInterface: new SimpleNetInterface(new LuminNetworkInterfaceName())
                );

            // Override for no companion app:
            LastDmeHostPrefixReply = new DmeHostPrefixReply {
                dme_host_prefix = "wifi"
            };
            // Use fallback location:
            Mxi.useFallbackLocation = true;
            Mxi.SetFallbackLocation(latitude: 37.3382082, longitude: -121.8863286); // MLLocation doesn't seem to return value after Start(), with permissions enabled.
        }