public static async Task <string> GetMobiledgeXAppFQDN() { MobiledgeXIntegration integration = new MobiledgeXIntegration(); try { await integration.RegisterAndFindCloudlet(); Debug.Log("FindCloudletReply.status = " + integration.FindCloudletReply.status); if (integration.FindCloudletReply.status == FindCloudletReply.FindStatus.FIND_FOUND) { return(integration.FindCloudletReply.fqdn); } else { return(""); } } //RegisterClientException is thrown if your app is not found catch (RegisterClientException rce) { Debug.LogError("RegisterClientException: " + rce.Message + "Inner Exception: " + rce.InnerException); return(""); } //FindCloudletException is thrown if there is no app instance in the selected region catch (FindCloudletException fce) { Debug.LogError("FindCloudletException: " + fce.Message + "Inner Exception: " + fce.InnerException); return(""); } }
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 }
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); } }
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 }
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. }
async void GetEdgeConnection() { mxi = new MobiledgeXIntegration(); await mxi.RegisterAndFindCloudlet(); udpSendPort = mxi.GetAppPort(LProto.L_PROTO_UDP).public_port; udpHost = mxi.GetHost(); Debug.Log("UDP HOST : " + udpHost); Debug.Log("UDP PORT : " + udpSendPort); SendUDPMessage("Hi, From a UDP Client to the UDP Server"); }
private void Awake() { DontDestroyOnLoad(this); if (instance == null) { instance = this; } else { Destroy(gameObject); } integration = new MobiledgeXIntegration(); }
// TODO: CancellationToken for Tasks to handle OnApplicationFocus, OnApplicationPause. public WsClient(MobiledgeXIntegration integration) { encoder = new UTF8Encoding(); ws = new ClientWebSocket(); this.integration = integration; receiveQueue = new ConcurrentQueue <string>(); receiveThread = new Thread(RunReceive); receiveThread.Start(); sendQueue = new BlockingCollection <ArraySegment <byte> >(); sendThread = new Thread(RunSend); sendThread.Start(); }
IEnumerator Start() { integration = new MobiledgeXIntegration(); #if UNITY_EDITOR GetEDGE(); yield break; #endif if (Application.internetReachability == NetworkReachability.NotReachable) { EdgePanel.SetActive(true); // Disables User Input NotConnectedToEdgePanel.SetActive(true); ErrorReason.text = "Not Connected to the internet"; ErrorSolution.GetComponentInChildren <Text>().text = "Restart the App and Connect to the Internet through Carrier Data."; ErrorPanel.SetActive(true); } yield return(StartCoroutine(MobiledgeX.LocationService.EnsureLocation())); GetEDGE(); }
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 }
string edgeCloudletStr = ""; // Connection url to Edge #region MonoBehaviour Callbacks // Use this for initialization IEnumerator Start() { integration = new MobiledgeXIntegration(); // Demo mode DME server to run MobiledgeX APIs, or if SIM card is missing // and a local DME cannot be located. Set to false if using a supported // SIM Card yield return(StartCoroutine(MobiledgeX.LocationService.EnsureLocation())); MobiledgeXAPICalls(); // Use local server, by IP. This must be started before use: if (useAltServer) { host = altServerHost; } server = "ws://" + host + ":" + port; webSocketClient = new MobiledgeXWebSocketClient(); gameSession = new GameSession(); gameSession.currentGs = new GameState(); gameSession.status = STATUS.LOBBY; }
async Task SceneFlow() { // Register Client edgeConnectionSteps.gameObject.SetActive(true); edgeConnectionSteps.registerClientStep.GetComponentInChildren <Image>().enabled = true; await Task.Delay(TimeSpan.FromSeconds(3)); edgeConnectionSteps.gameObject.SetActive(false); statusText.text = "Register Client"; infoText.text = InfoText(step); while (statusAnimator.GetInteger("Step") != 1) { await Task.Delay(TimeSpan.FromSeconds(.1)); } nextButton.interactable = false; mxi = new MobiledgeXIntegration(); try { statusText.text = "Register Client\n <b> Org Name:</b> " + settings.orgName + "\n <b>App Name:</b> " + settings.appName + "\n <b>App Version:</b> " + settings.appVers; await mxi.Register(); await Task.Delay(TimeSpan.FromSeconds(2)); statusAnimator.SetTrigger("Start"); await Task.Delay(TimeSpan.FromSeconds(.1)); statusText.color = Color.green; detailedInfoButton.gameObject.SetActive(true); detailedStatusText.text = "Register Client Status : " + mxi.RegisterStatus; statusText.text = "Verified"; } catch (RegisterClientException) { statusText.text = "Failed to verify"; errorPanel.SetActive(true); errorText.text = "Restart, Error in RegisterClient, check Console for more details"; return; } statusAnimator.SetTrigger("End"); await Task.Delay(TimeSpan.FromSeconds(2)); nextButton.interactable = true; while (statusAnimator.GetInteger("Step") != 2) { await Task.Delay(TimeSpan.FromSeconds(.1)); } edgeConnectionSteps.registerClientStep.GetComponentInChildren <Image>().enabled = false; edgeConnectionSteps.findCloudletStep.GetComponentInChildren <Image>().enabled = true; edgeConnectionSteps.gameObject.SetActive(true); await Task.Delay(TimeSpan.FromSeconds(3)); edgeConnectionSteps.gameObject.SetActive(false); detailedInfoButton.gameObject.SetActive(false); nextButton.interactable = false; statusAnimator.SetTrigger("Reset"); statusText.color = Color.black; statusText.text = ""; await Task.Delay(TimeSpan.FromSeconds(1.5)); // Find Cloudlet statusText.text = "Find Cloudlet"; await Task.Delay(TimeSpan.FromSeconds(1)); statusAnimator.SetTrigger("Start"); try { await mxi.FindCloudlet(); string portsString = "<b>Ports:</b>"; foreach (AppPort appPort in mxi.FindCloudletReply.ports) { portsString += "\n Port : (" + appPort.proto + ") " + appPort.public_port; } FindCloudletReply findCloudletReply = mxi.FindCloudletReply; detailedStatusText.text = "<b>FindCloudlet Status:</b> " + findCloudletReply.status + "\n<b>Cloudlet Location:</b> " + findCloudletReply.cloudlet_location.longitude + ", " + findCloudletReply.cloudlet_location.latitude + "\n<b>Application URL:</b> " + findCloudletReply.fqdn + "\n" + portsString; detailedInfoButton.gameObject.SetActive(true); planeAnimator.gameObject.GetComponent <MeshRenderer>().material.SetFloat("Alpha", 1); cameraAniamtor.SetTrigger("CameraMove"); await Task.Delay(TimeSpan.FromSeconds(1)); planeAnimator.enabled = true; nextButton.interactable = true; while (statusAnimator.GetInteger("Step") != 3) { await Task.Delay(TimeSpan.FromSeconds(.1)); } nextButton.interactable = false; await Task.Delay(TimeSpan.FromSeconds(1)); cameraAniamtor.SetTrigger("CameraBack"); await Task.Delay(TimeSpan.FromSeconds(1)); planeAnimator.gameObject.SetActive(false); statusText.text = "Cloudlet Found"; } catch (FindCloudletException) { errorPanel.SetActive(true); errorText.text = "Restart, Error in FindCloudlet, check Console for more details"; return; } statusAnimator.SetTrigger("End"); await Task.Delay(TimeSpan.FromSeconds(2)); statusAnimator.SetTrigger("Reset"); detailedInfoButton.gameObject.SetActive(false); statusText.text = ""; await Task.Delay(TimeSpan.FromSeconds(1.5)); // GetAppPort edgeConnectionSteps.findCloudletStep.GetComponentInChildren <Image>().enabled = false; edgeConnectionSteps.getAppPortStep.GetComponentInChildren <Image>().enabled = true; edgeConnectionSteps.gameObject.SetActive(true); await Task.Delay(TimeSpan.FromSeconds(3)); edgeConnectionSteps.gameObject.SetActive(false); statusText.text = "Connect to the desired port"; nextButton.interactable = true; while (statusAnimator.GetInteger("Step") != 4) { await Task.Delay(TimeSpan.FromSeconds(.1)); } statusText.text = "Select The desired protocol"; while (statusAnimator.GetInteger("Step") != 5) { await Task.Delay(TimeSpan.FromSeconds(.1)); } nextButton.interactable = false; await Task.Delay(TimeSpan.FromSeconds(1.5)); statusAnimator.SetTrigger("Start"); cameraAniamtor.SetTrigger("CameraMove"); await Task.Delay(TimeSpan.FromSeconds(1)); protoPanel.SetActive(true); await Task.Delay(TimeSpan.FromSeconds(1.5)); nextButton.interactable = false; while (statusAnimator.GetInteger("Step") != 6) { await Task.Delay(TimeSpan.FromSeconds(.1)); } protoPanel.SetActive(false); nextButton.interactable = false; cameraAniamtor.SetTrigger("CameraBack"); await Task.Delay(TimeSpan.FromSeconds(2)); statusText.text = "Port Found"; statusAnimator.SetTrigger("End"); await Task.Delay(TimeSpan.FromSeconds(1.5)); statusAnimator.SetTrigger("Reset"); // GetUrl edgeConnectionSteps.getAppPortStep.GetComponentInChildren <Image>().enabled = false; edgeConnectionSteps.getUrlStep.GetComponentInChildren <Image>().enabled = true; edgeConnectionSteps.gameObject.SetActive(true); await Task.Delay(TimeSpan.FromSeconds(3)); edgeConnectionSteps.gameObject.SetActive(false); await Task.Delay(TimeSpan.FromSeconds(1)); statusText.text = ""; IncrementStep(); cameraAniamtor.SetTrigger("CameraMove"); await Task.Delay(TimeSpan.FromSeconds(1)); L7protoPanel.SetActive(true); List <RectTransform> L7protos = (L7protoPanel.transform as RectTransform).Cast <RectTransform>().ToList(); switch (selectedProto) { case LProto.L_PROTO_HTTP: L7protos.Find(proto => proto.gameObject.name == "TCP").gameObject.SetActive(false); L7protos.Find(proto => proto.gameObject.name == "WebSocket").gameObject.SetActive(false); L7protos.Find(proto => proto.gameObject.name == "UDP").gameObject.SetActive(false); break; case LProto.L_PROTO_TCP: L7protos.Find(proto => proto.gameObject.name == "UDP").gameObject.SetActive(false); L7protos.Find(proto => proto.gameObject.name == "HTTP").gameObject.SetActive(false); break; case LProto.L_PROTO_UDP: L7protos.Find(proto => proto.gameObject.name == "TCP").gameObject.SetActive(false); L7protos.Find(proto => proto.gameObject.name == "WebSocket").gameObject.SetActive(false); L7protos.Find(proto => proto.gameObject.name == "HTTP").gameObject.SetActive(false); break; } while (statusAnimator.GetInteger("Step") != 8) { await Task.Delay(TimeSpan.FromSeconds(.1)); } L7protoPanel.SetActive(false); cameraAniamtor.SetTrigger("CameraBack"); await Task.Delay(TimeSpan.FromSeconds(1)); statusText.text = "Connected"; connectedParticleEffect.SetActive(true); detailedInfoButton.gameObject.SetActive(true); detailedStatusText.text = "GetUrl(\"" + selectedL7Proto + "\"):\n" + url; loadingBall.enabled = true; }
// Use this for initialization async Task Start() { // Demo mode DME server to run MobiledgeX APIs, or if SIM card is missing // and a local DME cannot be located. Set to false if using a supported // SIM Card. integration = new MobiledgeXIntegration(); integration.useDemo = true; integration.dmeHost = integration.me.GenerateDmeHostName(); // Use local server, by IP. This must be started before use: if (useAltServer) { host = altServerHost; } server = "ws://" + host + ":" + port; theBall = GameObject.FindGameObjectWithTag("Ball"); players = GameObject.FindGameObjectsWithTag("Player"); client = new WsClient(); gameSession.currentGs = new GameState(); gameSession.status = STATUS.LOBBY; // Create a Mex Paddle (for local user) from the Prefab: ghostPlayer = (GameObject)Instantiate(Resources.Load("PaddleGhost")); ghostBall = (GameObject)Instantiate(Resources.Load("BallGhost")); uiG = GameObject.FindGameObjectWithTag("UIConsole"); uiConsole = uiG.GetComponent <Text>(); // Attach a listener to the Room ID input field. roomIdInput = GameObject.Find("InputFieldRoomId").GetComponent <InputField>(); roomIdInput.onEndEdit.AddListener(ConnectToServerWithRoomId); try { // Register and find cloudlet: uiConsole.text = "Registering to DME: "; edgeCloudletStr = await RegisterAndFindCloudlet(); stopWatch.Start(); clog("Found Cloudlet from DME result: [" + edgeCloudletStr + "]"); // 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(); //bool verifiedLocation = false; // Decide what to do with location status. clog("VerifiedLocation: " + verifiedLocation); } catch (HttpException httpe) // HTTP status, and REST API call error codes. { // server error code, and human readable message: clog("RegisterClient Exception: " + httpe.Message + ", HTTP StatusCode: " + httpe.HttpStatusCode + ", API ErrorCode: " + httpe.ErrorCode + "\nStack: " + httpe.StackTrace); } catch (DmeDnsException de) { // This app should fallback to public cloud, as the DME doesn't exist for your // SIM card + carrier. clog("Cannot register to DME host: " + de.Message + ", Stack: " + de.StackTrace); if (de.InnerException != null) { clog("Original Exception: " + de.InnerException.Message); } // Handle fallback to public cloud application server. } catch (HttpRequestException httpre) { clog("RegisterClient HttpRequest Exception" + httpre.Message + "\nStack Trace: " + httpre.StackTrace); } catch (Exception e) { clog("Unexpected Exception: " + e.StackTrace); } }