public async Task <FindCloudletReply> FindCloudlet() { // Location is ephemeral, so retrieve a new location from the platform. May return 0,0 which is // technically valid, though less likely real, as of writing. Loc loc = await GetLocationFromDevice(); // If MEX is reachable on your SIM card: string aCarrierName = GetCarrierName(); string eCarrierName; if (me.useOnlyWifi) // There's no host (PC, UnityEditor, etc.)... { eCarrierName = carrierName; } else { if (aCarrierName == "" || aCarrierName == null) { Debug.Log("Missing CarrierName for FindCloudlet."); return(null); } eCarrierName = aCarrierName; } FindCloudletRequest req = me.CreateFindCloudletRequest(eCarrierName, loc); FindCloudletReply reply = await me.FindCloudlet(req); return(reply); }
async Task <bool> DoFindCloudlet() { bool ok = false; MatchingEngine dme = mexSample.dme; FindCloudletReply reply = null; try { var deviceSourcedLocation = await LocationService.RetrieveLocation(); if (deviceSourcedLocation == null) { Debug.Log("FindCloudlet must have a device sourced location to send."); return(false); } Debug.Log("Device sourced location: Lat: " + deviceSourcedLocation.latitude + " Long: " + deviceSourcedLocation.longitude); var findCloudletRequest = dme.CreateFindCloudletRequest( mexSample.carrierName, mexSample.devName, mexSample.appName, mexSample.appVers, deviceSourcedLocation); if (findCloudletRequest == null) { Debug.Log("Failed to create request."); ok = false; return(ok); } reply = await dme.FindCloudlet(mexSample.host, mexSample.port, findCloudletRequest); statusContainer.Post("FindCloudlet Reply status: " + reply.status); } catch (System.Net.WebException we) { Console.WriteLine(we.StackTrace); statusContainer.Post(we.Source + ", WebException: " + we.Message); statusContainer.Post(we.StackTrace); } finally { if (reply != null) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(FindCloudletReply)); MemoryStream ms = new MemoryStream(); serializer.WriteObject(ms, reply); string jsonStr = Util.StreamToString(ms); statusContainer.Post("GPS Cloudlet location: " + jsonStr + ", fqdn: " + reply.fqdn); // The list of registered edge cloudlets that the app can use: if (reply.ports.Length == 0) { statusContainer.Post("There are no app ports for this app's edge cloudlets."); } else { statusContainer.Post("Cloudlet app ports:"); foreach (var appPort in reply.ports) { statusContainer.Post( "Protocol: " + appPort.proto + ", internal_port: " + appPort.internal_port + ", public_port: " + appPort.public_port + ", path_prefix: " + appPort.path_prefix + ", fqdn_prefix: " + appPort.fqdn_prefix ); } } } } return(ok); }