~/incubator-brpc/example/echo_c++$ git diff
diff --git a/example/echo_c++/client.cpp b/example/echo_c++/client.cpp
index 337aa6e9..0df24399 100644
--- a/example/echo_c++/client.cpp
+++ b/example/echo_c++/client.cpp
@@ -23,8 +23,7 @@
#include <brpc/channel.h>
#include "echo.pb.h"
-DEFINE_string(attachment, "", "Carry this along with requests");
-DEFINE_string(protocol, "baidu_std", "Protocol type. Defined in src/brpc/options.proto");
+DEFINE_string(protocol, "http", "Protocol type. Defined in src/brpc/options.proto");
DEFINE_string(connection_type, "", "Connection type. Available values: single, pooled, short");
DEFINE_string(server, "0.0.0.0:8000", "IP Address of server");
DEFINE_string(load_balancer, "", "The algorithm for load balancing");
@@ -64,12 +63,10 @@ int main(int argc, char* argv[]) {
example::EchoResponse response;
brpc::Controller cntl;
- request.set_message("hello world");
+ request.set_message("hello server123");
+ request.set_length(strlen("hello server123"));
cntl.set_log_id(log_id ++); // set by user
- // Set attachment which is wired to network directly instead of
- // being serialized into protobuf messages.
- cntl.request_attachment().append(FLAGS_attachment);
// Because `done'(last parameter) is NULL, this function waits until
// the response comes back or error occurs(including timedout).
@@ -77,8 +74,8 @@ int main(int argc, char* argv[]) {
if (!cntl.Failed()) {
LOG(INFO) << "Received response from " << cntl.remote_side()
<< " to " << cntl.local_side()
- << ": " << response.message() << " (attached="
- << cntl.response_attachment() << ")"
+ << ": " << response.message() << " (length="
+ << response.length() << ")"
<< " latency=" << cntl.latency_us() << "us";
} else {
LOG(WARNING) << cntl.ErrorText();
diff --git a/example/echo_c++/echo.proto b/example/echo_c++/echo.proto
index 2b39627f..8851b2e2 100644
--- a/example/echo_c++/echo.proto
+++ b/example/echo_c++/echo.proto
@@ -22,10 +22,12 @@ option cc_generic_services = true;
message EchoRequest {
required string message = 1;
+ required int32 length = 2;
};
message EchoResponse {
required string message = 1;
+ required int32 length = 2;
};
service EchoService {
diff --git a/example/echo_c++/server.cpp b/example/echo_c++/server.cpp
index 41ffd0b1..549737f8 100644
--- a/example/echo_c++/server.cpp
+++ b/example/echo_c++/server.cpp
@@ -22,7 +22,6 @@
#include <brpc/server.h>
#include "echo.pb.h"
-DEFINE_bool(echo_attachment, true, "Echo attachment as well");
DEFINE_int32(port, 8000, "TCP Port of this server");
DEFINE_string(listen_addr, "", "Server listen address, may be IPV4/IPV6/UDS."
" If this is set, the flag port will be ignored");
@@ -57,20 +56,11 @@ public:
<< "] from " << cntl->remote_side()
<< " to " << cntl->local_side()
<< ": " << request->message()
- << " (attached=" << cntl->request_attachment() << ")";
+ << " (length=" << request->length() << ")";
// Fill response.
- response->set_message(request->message());
-
- // You can compress the response by setting Controller, but be aware
- // that compression may be costly, evaluate before turning on.
- // cntl->set_response_compress_type(brpc::COMPRESS_TYPE_GZIP);
-
- if (FLAGS_echo_attachment) {
- // Set attachment which is wired to network directly instead of
- // being serialized into protobuf messages.
- cntl->response_attachment().append(cntl->request_attachment());
- }
+ response->set_message("hello client");
+ response->set_length(strlen("hello client"));
}
};
} // namespace example