Exemplo n.º 1
0
        async Task GetEDGE()
        {
            integration = new MobiledgeXIntegration();
#if UNITY_EDITOR
            integration.UseWifiOnly(true);
#endif
            try
            {
                bool cloudletFound = await integration.RegisterAndFindCloudlet();

                if (cloudletFound)
                {
                    appManager.EnableInteraction();
                    ConnectedToEdgePanel.SetActive(true);
                    Loc cloudletLocation = integration.FindCloudletReply.cloudlet_location;
                    Loc userLocation     = MobiledgeX.LocationService.RetrieveLocation();
                    distanceToCloudlet = distance(cloudletLocation.latitude, cloudletLocation.longitude, userLocation.latitude, userLocation.longitude).ToString("f0") + " mi";
                }
            }

            catch (RegisterClientException) // In case we don't support the detected carrierName  (In the generated dme)
            {
                integration.UseWifiOnly(true);
                await integration.RegisterAndFindCloudlet();
            }
            catch (FindCloudletException)  // GPS Location Error
            {
                EdgePanel.SetActive(true); // Disables User Input
                NotConnectedToEdgePanel.SetActive(true);
                ErrorReason.text = "Location Permission Denied";
                ErrorSolution.GetComponentInChildren <Text>().text = "Allow Location Permission in your settings & Restart the App";
                ErrorPanel.SetActive(true);
            }
        }
Exemplo n.º 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
    }
Exemplo n.º 3
0
        /// <summary>
        /// Connect to your EdgeMultiplay server based on location and carrier info
        /// <para>
        /// use <b>public override void OnConnectionToEdge()</b>  to get the server response
        /// </para>
        /// </summary>
        /// <param name="useAnyCarrierNetwork"> set to true for connection based on location info only </param>
        /// <param name="useFallBackLocation"> set to true to use overloaded location sat in setFallbackLocation()</param>
        /// <param name="path"> You can specify a path for your connection to be verified on the server side </param>
        /// <returns> Connection Task, use OnConnectionToEdge() to listen to the async task result </returns>
        public async Task ConnectToServer(bool useAnyCarrierNetwork = true, bool useFallBackLocation = false, string path = "")
        {
            if (useLocalHostServer)
            {
                try
                {
                    gameSession = new Session();
                    wsClient    = new MobiledgeXWebSocketClient();
                    Uri uri = new Uri("ws://" + hostIPAddress + ":" + defaultEdgeMultiplayServerTCPPort + path);
                    if (wsClient.isOpen())
                    {
                        wsClient.Dispose();
                        wsClient = new MobiledgeXWebSocketClient();
                    }
                    await wsClient.Connect(@uri);

                    EdgeMultiplayCallbacks.connectedToEdge();
                }
                catch (Exception e)
                {
                    EdgeMultiplayCallbacks.failureToConnect(e.Message);
                    Debug.LogError("EdgeMultiplay: Failed to connect to your Local Host, Check console for more details");
                }
            }
            else
            {
                try
                {
                    gameSession = new Session();
                    integration.UseWifiOnly(useAnyCarrierNetwork);
                    integration.useFallbackLocation = useFallBackLocation;
                    wsClient = new MobiledgeXWebSocketClient();
                    await integration.RegisterAndFindCloudlet();

                    integration.GetAppPort(LProto.L_PROTO_TCP);
                    string url = integration.GetUrl("ws") + path;
                    Uri    uri = new Uri(url);
                    if (wsClient.isOpen())
                    {
                        wsClient.Dispose();
                        wsClient = new MobiledgeXWebSocketClient();
                    }
                    await wsClient.Connect(@uri);

                    EdgeMultiplayCallbacks.connectedToEdge();
                }
                catch (Exception e)
                {
                    EdgeMultiplayCallbacks.failureToConnect(e.Message);
                    Debug.LogError("EdgeMultiplay: Failed to connect to Edge, Check console for more details");
                }
            }
        }
Exemplo n.º 4
0
    async void GetEdgeConnection()
    {
        mxi = new MobiledgeXIntegration();
        try
        {
            await mxi.RegisterAndFindCloudlet();
        }
        catch (DmeDnsException)
        {
            mxi.UseWifiOnly(true);
            await mxi.RegisterAndFindCloudlet();
        }

        mxi.GetAppPort(LProto.L_PROTO_TCP);
        string url = mxi.GetUrl("ws");

        Debug.Log("WebSocket URL is : " + url);
        await StartWebSocket(url);

        //wsClient.Send("WebSocketMsg");// You can send  Text or Binary messages to the WebSocket Server
    }
Exemplo n.º 5
0
        public async void MobiledgeXAPICalls()
        {
            integration.UseWifiOnly(true);
            // RegisterAndFindCloudlet and VerifyLocation:
            FindCloudletReply findCloudletReply;

            try
            {
                gameManager.uiConsole.text = "Registering to DME: ";
                bool registeredAndFoundCloudlet = await integration.RegisterAndFindCloudlet();

                if (!registeredAndFoundCloudlet)
                {
                    gameManager.clog("Unable to register and find cloudlet");
                    return;
                }
                stopWatch.Start();

                findCloudletReply = integration.FindCloudletReply;
                gameManager.clog("FindCloudletReply: status: " + findCloudletReply.status + ", fqdn: " + findCloudletReply.fqdn);

                // This might be inside a thread update loop. Re-register client and check periodically.
                // VerifyLocation will fail if verification is unavailable at the carrier.
                bool verifiedLocation = await integration.VerifyLocation();

                // Decide what to do with location status.
                gameManager.clog("VerifiedLocation: " + verifiedLocation);
            }
            catch (RegisterClientException rce)
            {
                gameManager.clog("RegisterClientException: " + rce.Message + ". Make sure OrgName, AppName, and AppVers are correct.");
                return;
            }
            catch (FindCloudletException fce)
            {
                gameManager.clog("FindCloudletException: " + fce.Message + ". Make sure you have an app instance deployed to your region and carrier network");
                return;
            }
            catch (DmeDnsException de)
            {
                // This app should fallback to public cloud, as the DME doesn't exist for your
                // SIM card + carrier.
                gameManager.clog("Cannot register to DME host: " + de.Message + ", Stack: " + de.StackTrace);
                if (de.InnerException != null)
                {
                    gameManager.clog("Original Exception: " + de.InnerException.Message);
                }
                // Handle fallback to public cloud application server.
                return;
            }
            catch (Exception e)
            {
                gameManager.clog("Unexpected Exception: " + e.StackTrace);
                return;
            }

            // GetAppPort
            AppPort appPort;

            try
            {
                appPort = integration.GetAppPort(LProto.L_PROTO_TCP);
            }
            catch (AppPortException ape)
            {
                gameManager.clog("Unabled to get AppPort. AppPortException: " + ape.Message);
                return;
            }
            if (appPort == null)
            {
                gameManager.clog("GetAppPort returned null");
                return;
            }

            // GetUrl
            try
            {
                edgeCloudletStr = integration.GetUrl("ws");
                gameManager.clog("Found Cloudlet from DME result: [" + edgeCloudletStr + "]");
            }
            catch (GetConnectionException gce)
            {
                gameManager.clog("Unabled to get url. GetConnectionException " + gce.Message);
                return;
            }

            // NetTest
            netTest = new NetTest(integration.matchingEngine);
            foreach (AppPort ap in findCloudletReply.ports)
            {
                gameManager.clog("Port: proto: " + ap.proto + ", prefix: " + ap.fqdn_prefix + ", path_prefix: " + ap.path_prefix + ", port: " + ap.public_port);

                NetTest.Site site;
                // We're looking for one of the TCP app ports:
                if (ap.proto == LProto.L_PROTO_TCP)
                {
                    // Add to test targets.
                    if (ap.path_prefix == "")
                    {
                        site = new NetTest.Site
                        {
                            host = integration.GetHost(ap),
                            port = integration.GetPort(ap)
                        };
                        site.testType = NetTest.TestType.CONNECT;
                    }
                    else
                    {
                        site = new NetTest.Site
                        {
                            L7Path = integration.GetUrl("", ap)
                        };
                        site.testType = NetTest.TestType.CONNECT;
                    }
                    if (useAltServer)
                    {
                        site.host = host;
                    }
                    l7Path = site.L7Path;
                    netTest.sites.Enqueue(site);
                }
            }
            netTest.doTest(true);
        }