/// <summary> /// This method front ends a gRPC client method which makes a call to the remote gRPC server, passing a POINT /// Message type, and subsequently having the server response be the Feature Point's Name. /// Essentially - Client single REQUEST/Server single RESPONSE /// </summary> public async void GetSingleFeature() { ClearTMPTextChildren(); var pointOfInterest = new Routeguide.Point { Latitude = 409146138, Longitude = -746188906 }; await _routeGuideClient.GetFeature(pointOfInterest); Debug.Log("GetSingleFeature Finished"); }
private Routeguide.Point randomPointOfInterest() { var lat = (UnityEngine.Random.Range(1, 180) - 90) * 1e7; var lon = (UnityEngine.Random.Range(1, 360) - 180) * 1e7; var randomPointOfInterest = new Routeguide.Point { Latitude = Convert.ToInt32(lat), Longitude = Convert.ToInt32(lon) }; return(randomPointOfInterest); }
/// This method front ends a gRPC client method which makes a call to the remote gRPC server, passing a SET of /// two or more randomly generated POINTs as an asynchronous STREAM. /// The response from the gRPC server is calculated summary (string) of the distance between all the /// points. /// Essentially - Client-side asynchronous STREAM/Server single Response /// </summary> public async void GetPointsRouteSummary() { ClearTMPTextChildren(); var pointCount = UnityEngine.Random.Range(1, 100) + 1; // Traverse at least two points var points = new Routeguide.Point[pointCount]; for (int i = 0; i < pointCount; i++) { points[i] = randomPointOfInterest(); } Debug.Log("GetPointsRouteSummary traversing " + points.Length.ToString() + " points"); await _routeGuideClient.RecordRoute(points); Debug.Log("GetPointsRouteSummary Finished"); }
private static void TestNormal(string server) { var channel = new Grpc.Core.Channel(server, ChannelCredentials.Insecure); var client = new RouteGuideClient(channel); // Looking for a valid feature var pt = new Routeguide.Point(); Stopwatch sw = Stopwatch.StartNew(); for (int i = 0; i < 20; i++) { var f = client.GetFeature(pt); //Console.WriteLine($" {f} {sw.ElapsedMilliseconds}"); } sw.Stop(); Console.WriteLine($".NET Elapsed {sw.ElapsedMilliseconds}"); Console.WriteLine("Press any key to exit..."); channel.ShutdownAsync().Wait(); }
/// <summary> /// This method handles the task of calling the remote gRPC Service GetFeature, passing a Message Type of /// Point, and receiving back a single Message type of Feature (which contains a string name and its corresponding /// Point /// </summary> /// <param name="pointOfInterest">A single Routeguide Point (which contains a Lat/Long value)</param> /// <returns></returns> public async Task GetFeature(Routeguide.Point pointOfInterest) { Debug.Log("GetFeature Client latitude: " + pointOfInterest.Latitude + ", longitude: " + pointOfInterest.Longitude); try { var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var returnVal = await _client.GetFeatureAsync(pointOfInterest, cancellationToken : cts.Token); _myRouteGuideUiHandler.AddTextToUi(returnVal.Name, false); } catch (RpcException e) { _myRouteGuideUiHandler.AddTextToUi("GetFeature Service is unavailable. " + e.Message, false); } #if DEBUG Debug.Log("GetFeature Finished"); #endif }
/// <summary> /// This method front ends a gRPC client method which makes a call to the remote gRPC server, passing a SET of /// Two POINTs within a Rectangle Message Type. /// The response from the gRPC server is an asynchronous STREAM of Feature Message types /// Essentially - Single Client REQUEST/Server-side asynchronous response STREAM /// </summary> public async void GetMultipleFeatures() { ClearTMPTextChildren(); var pointOfInterestLo = new Routeguide.Point { Latitude = 400000000, Longitude = -750000000 }; var pointOfInterestHi = new Routeguide.Point { Latitude = 420000000, Longitude = -730000000 }; var areaOfInterest = new Routeguide.Rectangle { Lo = pointOfInterestLo, Hi = pointOfInterestHi, }; await _routeGuideClient.ListFeatures(areaOfInterest); Debug.Log("GetMultipleFeatures Finished"); }