protobuf-c-rpc server and grpc client

774 views
Skip to first unread message

kab...@gmail.com

unread,
Aug 17, 2016, 9:13:23 AM8/17/16
to grpc.io
Hi everybody,

I worked in a project that implemented a protocol buffers RPC in C using protobuf-c-rpc and now I'm trying develop a C++ or NodeJs client using grpc but it not working.


Nathaniel Manista

unread,
Aug 17, 2016, 9:52:32 AM8/17/16
to kab...@gmail.com, grpc.io
On Wed, Aug 17, 2016 at 6:13 AM, <kab...@gmail.com> wrote:
I worked in a project that implemented a protocol buffers RPC in C using protobuf-c-rpc and now I'm trying develop a C++ or NodeJs client using grpc but it not working.

Kabloc Vacavoa

unread,
Aug 17, 2016, 2:35:17 PM8/17/16
to Nathaniel Manista, grpc.io
OK, Sorry...

Firstly sorry about my English...

I have a project made in C that use protobuf-c-rpc to create a RPC procedures, that interfaces with others application in C normally.

Now I need to do an application in NodeJs that uses the same interface, I tried by using protobuf-rpc:

<CODE>

var express = require('express');
var app = express();
var ProtoBuf = require('protobufjs');
    ProtoBuf.Rpc = require('protobuf-rpc');

var builder = ProtoBuf.loadProtoFile("ControllerMessage.proto");
var My_controller = builder.build('MyPackage');
var controller_svc = new ProtoBuf.Rpc(My_controller.Controller, {
transport: new ProtoBuf.Rpc.Transport.Xhr( {sync: true} ),
});

app.get('/have_pswd', function (req, res) {
var serv_req = new My_controller.Void();
controller_svc.HavePassword(serv_req, function(error, serv_res) {
  if (error !== null)
return res.status(500).send('error');
res.json(serv_res);
});
});

var server = app.listen(9017, function(){
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});

</CODE>

When I send a GET to localhost:9017/have_pswd, I have a error(500).


After that I tried by using grpc++:

protoc --proto_path=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ControllerMessage.proto 
protoc --proto_path=. --cpp_out=. ControllerMessage.proto 

<CODE>

#include <grpc++/grpc++.h>

#include "ControllerMessage.pb.h"
#include "ControllerMessage.grpc.pb.h"

int main (int argc, char* argv[])
{
   std::unique_ptr<MyPackage::Controller::Stub>
         stub(MyPackage::Controller::NewStub(
                 grpc::CreateChannel("localhost:5558", grpc::InsecureChannelCredentials())));
   grpc::ClientContext cxt;
   MyPackage::Void req;
   MyPackage::Boolean res;

   stub->HavePassword(&cxt, req, &res);
}


</CODE>

And on debug the line "stub->HavePassword(&cxt, req, &res);" make me wait forever.

I would like to know what I did wrong...

Thanks...
--
--
echo Gur orfg jnl gb cerqvpg gur shgher vf gb vairag vg: -- Nyna Xnl | tr N-ZA-Mn-za-m: A-Za-z.

kab...@gmail.com

unread,
Aug 18, 2016, 7:39:43 AM8/18/16
to grpc.io, nath...@google.com, kab...@gmail.com
I have new information about this problem...

With a little modification on NodeJs code I got this error:

Modification:
app.get('/have_pswd', function (req, res) {
var serv_req = new My_controller.Void();
controller_svc.HavePassword(serv_req, function(error, serv_res) {
  if (error !== null) throw error;
res.json(serv_res);
});
});

Error:
 RangeError: offset is not uint
    at checkOffset (buffer.js:580:11)
    at SlowBuffer.Buffer.readUInt32LE (buffer.js:642:5)
    at null.rpcImpl (/home/kabloc/work/server_controller/node_modules/protobuf-rpc/index.js:322:39)
    at clazz.ServicePrototype.(anonymous function) [as HavePassword] (/home/kabloc/work/server_controller/node_modules/protobufjs/dist/protobuf.js:4050:38)
    at EventEmitter.app.listen.host (/home/kabloc/work/server_controller/index.js:35:17)
    at EventEmitter.emit (events.js:92:17)
    at null._onTimeout (/home/kabloc/work/server_controller/node_modules/protobuf-rpc/index.js:86:50)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

Somebody have an idea about it?

Michael Lumish

unread,
Aug 18, 2016, 12:41:33 PM8/18/16
to kab...@gmail.com, grpc.io, nath...@google.com
protobuf-c-rpc and protobuf-rpc are not related to gRPC. Based on your use of ProtoBuf.Rpc.Transport.Xhr, it looks like they are using XML HTTP Requests instead. The C++ gRPC client will not work with one of those servers because it uses a completely different protocol.

--
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 grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/32e31975-c088-437f-8f27-d5d7a7df7d30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kabloc Vacavoa

unread,
Aug 18, 2016, 1:10:16 PM8/18/16
to Michael Lumish, grpc.io, Nathaniel Manista
Can I work with gRPC in C? Because I can refactor my server, that is made in C, to communicate whit NodeJs client.

Any ideas?

To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/32e31975-c088-437f-8f27-d5d7a7df7d30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

raut...@gmail.com

unread,
Aug 18, 2016, 7:11:58 PM8/18/16
to grpc.io, mlu...@google.com, nath...@google.com, kab...@gmail.com


On Thursday, 18 August 2016 10:10:16 UTC-7, Kabloc Vacavoa wrote:
Can I work with gRPC in C? Because I can refactor my server, that is made in C, to communicate whit NodeJs client.

Any ideas?
 
No because gRPC works with proto3 which does not have a C compiler.
gRPC core is in C, so you do have low level APIs exposed under grpc/include/grpc but it means you would have to write a lot of boiler plate code in C.

If you want to use C, proto2 is your only option for now. Or you may have to write a proto2 to proto3 stub via a wrapper abstraction in library, which eventually calls proto3 based gRPC calls.

Good luck
 

To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/32e31975-c088-437f-8f27-d5d7a7df7d30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages