public void SetAppPort(string protoString) { try { switch (protoString) { case "tcp": selectedProto = LProto.L_PROTO_TCP; mxi.GetAppPort(selectedProto); break; case "http": selectedProto = LProto.L_PROTO_HTTP; mxi.GetAppPort(selectedProto); break; case "udp": selectedProto = LProto.L_PROTO_UDP; mxi.GetAppPort(selectedProto); break; } } catch (AppPortException) { errorPanel.SetActive(true); errorText.text = "Error in GetAppPort, check the Console for more details"; return; } }
/// <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"); } } }
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 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 }
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"); }
public string UriBasedOnConnectionMode() { AppPort appPort; string url; switch (connectionMode) { case ConnectionMode.WebSocket: appPort = integration.GetAppPort(LProto.L_PROTO_TCP); url = integration.GetUrl("ws"); return(url); case ConnectionMode.Rest: appPort = integration.GetAppPort(LProto.L_PROTO_TCP); url = integration.GetUrl("http"); return(url); default: return(""); } }
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 }
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); }