Hello.
I am a student and English is not my first language, so I would appreciate 
it if you could be considerate even if it is difficult to read.
I'm struggling with making a Simple send & receive message program using 
Grpc.
I'm trying to making [Grpc Server as C++] & [Grpc Client as c#].

And I use Helloworld.proto File in Grpc Repository.
And I use Typical Helloworld Example From Grpc Repository.

c# client Connectcs to c++ server WELL but When c++ server trying to 
set_message like
 reply->set_message(prefix + request->name());
Some Error Occurs.

I want to know how I can solve those error.
And I don't know why this error occrus.


[Error]
Client Connect to Server Well But When Server Set message to Client
"Run-Time Check Failure #2- Stack around the variable 'true_factory' was 
corrupted"
"Run-Time Check Failure #2- Stack around the variable 'r' was corrupted"
"Run-Time Check Failure #2- Stack around the variable 'r' was corrupted"
"Run-Time Check Failure #2- Stack around the variable 'true_factory  ' was 
corrupted"
"Run-Time Check Failure #2- Stack around the variable 'r' was corrupted"
"Run-Time Check Failure #2- Stack around the variable 'r' was corrupted"
"Run-Time Check Failure #2- Stack around the variable 'r' was corrupted"
....
This Error Ocuurs in Server(C++).



[Version]
---------------------------------------------------------------------------------------------------------------------------------------------------------
*C++(Server Side) :  *
* -> I build it myself using cmake-gui and generate VS2017 sln. And build 
protobuf myself when builing grpc.*

* GRPC : 1.54.0 (https://github.com/grpc/grpc/releases/tag/v1.54.0)
* Protobuf : 3.21.12
-> compile protobuf file using protoc and grpc_cpp_plugin (build myslef)
---------------------------------------------------------------------------------------------------------------------------------------------------------
*C#(Client Side) :  *
*-> Use Nuget Package *

* Protobuf : 3.21.12(same version as c++ side, only difference is c++ 
protobuf build myslef, and c# protobuf is nuget package)
-> compile protobuf file using nuget package
* Grpc.Core : 2.46.6
* Grpc.Tools : 2.46.6
---------------------------------------------------------------------------------------------------------------------------------------------------------

[helloworld.proto]
syntax = "proto3";

package helloworld;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}

[c++ Program]
#include <iostream>
#include <memory>
#include <string>

#include <grpcpp/ext/proto_server_reflection_plugin.h>
#include <grpcpp/grpcpp.h>
#include <grpcpp/health_check_service_interface.h>

#ifdef BAZEL_BUILD
#include "examples/protos/helloworld.grpc.pb.h"
#else
#include "helloworld.grpc.pb.h"
#endif

using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using helloworld::Greeter;
using helloworld::HelloReply;
using helloworld::HelloRequest;

// Logic and data behind the server's behavior.
class GreeterServiceImpl final : public Greeter::Service {
    Status SayHello(ServerContext* context, const HelloRequest* request,
        HelloReply* reply) override {
        std::string prefix("Hello ");
        reply->set_message(prefix + request->name());
        return Status::OK;
    }
};

void RunServer() {
    std::string server_address("0.0.0.0:9000");
    GreeterServiceImpl service;

    grpc::EnableDefaultHealthCheckService(true);
    grpc::reflection::InitProtoReflectionServerBuilderPlugin();
    ServerBuilder builder;
    // Listen on the given address without any authentication mechanism.
    builder.AddListeningPort(server_address, 
grpc::InsecureServerCredentials());
    // Register "service" as the instance through which we'll communicate 
with
    // clients. In this case it corresponds to an *synchronous* service.
    builder.RegisterService(&service);
    // Finally assemble the server.
    std::unique_ptr<Server> server(builder.BuildAndStart());
    std::cout << "Server listening on " << server_address << std::endl;

    // Wait for the server to shutdown. Note that some other thread must be
    // responsible for shutting down the server for this call to ever 
return.
    server->Wait();
}

int main(int argc, char** argv) {
    RunServer();

    return 0;
}

[c# program]
 // Set up gRPC client
            Channel channel = new Channel("localhost:9000", 
ChannelCredentials.Insecure);
            var client = new Greeter.GreeterClient(channel);

            // Call the service
            var req = new HelloRequest { Name = "C#" };
            var resp = client.SayHello(req);
            foreach (string msg in resp.Message) {
                Console.WriteLine(msg);
            }

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/0310e544-c1c4-4c24-899d-52ca193db2e3n%40googlegroups.com.

Reply via email to