Commit 57fda234 authored by AlexStocks's avatar AlexStocks

Add: protobuf test example

parent 1e853451
......@@ -22,7 +22,7 @@ To run the example, start the server:
Next, start the client:
$ cd tcp-echo/client/ && sh assembly/linux/test.sh && cd target/linux/echo_client-0.3.07-20161009-1634-test/ && sh bin/load.sh start
$ cd echo/tcp-echo/client/ && sh assembly/linux/test.sh && cd target/linux/echo_client-0.3.07-20161009-1634-test/ && sh bin/load.sh start
## getty example2: ws-echo ##
---
......@@ -42,3 +42,24 @@ Next, start the go client:
Or start the js client:
$ cd echo/ws-echo/js-client/ && open index.html in a internet browser(like chrome or ie or firefox etc).
## getty example3: rpc ##
---
This example shows a simple rpc client and server.
The server sends back rpc response to client. The client sends rpc requests to the rpc server and prints all messages received.
To run the example on linux, start the server:
$ cd rpc/server/ && sh assembly/linux/test.sh && cd target/linux/rpc_server-0.9.2-20180806-1559-test/ && sh bin/load.sh start
Next, start the go client:
$ cd rpc/client/ && sh assembly/linux/test.sh && cd target/linux/rpc_client-0.9.2-20180806-1559-test/ && sh bin/load.sh start
What's more, if you run this example on mac, the server compile command should be:
$ cd rpc/server/ && sh assembly/mac/test.sh && cd target/darwin/rpc_server-0.9.2-20180806-1559-test/ && sh bin/load.sh start
$ cd rpc/client/ && sh assembly/mac/test.sh && cd target/darwin/rpc_client-0.9.2-20180806-1559-test/ && sh bin/load.sh start
......@@ -107,7 +107,7 @@ func initSignal() {
}
}
func test() {
func testJSON() {
var (
err error
testResult string
......@@ -126,7 +126,7 @@ func test() {
log.Error("client.Call(TestRpc::Add) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestRpc::Add(1) = res:%s", addResult)
log.Info("TestRpc::Add(1) = res:%d", addResult)
var errResult int
err = client.Call(rpc.CodecJson, "127.0.0.1:20000", "TestRpc", "Err", 2, &errResult)
......@@ -137,3 +137,43 @@ func test() {
}
log.Info("TestRpc::Err(2) = res:%s", errResult)
}
func testProtobuf() {
var (
err error
testResult string
)
param := TestABC{"aaa", "bbb", "ccc"}
err = client.Call(rpc.CodecProtobuf, "127.0.0.1:20000", "TestRpc", "Test", param, &testResult)
if err != nil {
log.Error("client.Call(TestRpc::Test) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestRpc::Test(param:%#v) = res:%s", param, testResult)
var addResult int
err = client.Call(rpc.CodecProtobuf, "127.0.0.1:20000", "TestRpc", "Add", 1, &addResult)
if err != nil {
log.Error("client.Call(TestRpc::Add) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestRpc::Add(1) = res:%d", addResult)
var errResult int
err = client.Call(rpc.CodecProtobuf, "127.0.0.1:20000", "TestRpc", "Err", 2, &errResult)
if err != nil {
// error test case, this invocation should step into this branch.
log.Error("client.Call(TestRpc::Err) = error:%s", jerrors.ErrorStack(err))
return
}
log.Info("TestRpc::Err(2) = res:%s", errResult)
}
func test() {
gxlog.CInfo("start to run json rpc example:\n")
testJSON()
time.Sleep(2e9)
gxlog.CInfo("start to run protobuf rpc example:\n")
testJSON()
}
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.8.4"
Version = "0.9.2"
)
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.8.4"
Version = "0.9.2"
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment