Skip to content

Commit

Permalink
Merge pull request #416 from TarsCloud/fix/examples
Browse files Browse the repository at this point in the history
fix(examples): custom proto server and GetCommunicator replace NewCom…
  • Loading branch information
lbbniu authored Jan 13, 2023
2 parents adc0811 + 8f3a59d commit d254aa8
Show file tree
Hide file tree
Showing 20 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion examples/CmakeServer/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := fmt.Sprintf("StressTest.EchoTestServer.EchoTestObj@tcp -h 127.0.0.1 -p 10015 -t 60000")
app := new(StressTest.EchoTest)
comm.StringToProxy(obj, app)
Expand Down
2 changes: 1 addition & 1 deletion examples/ContextTestServer/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func main() {
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := fmt.Sprintf("StressTest.ContextTestServer.ContextTestObj@tcp -h 127.0.0.1 -p 10028 -t 60000")
app := new(StressTest.ContextTest)
comm.StringToProxy(obj, app)
Expand Down
2 changes: 1 addition & 1 deletion examples/ContextTestServer/debugtool/dumpstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func main() {
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := fmt.Sprintf("StressTest.ContextTestServer.ContextTestObjObj@tcp -h 127.0.0.1 -p 10014 -t 60000")
app := new(adminf.AdminF)
comm.StringToProxy(obj, app)
Expand Down
10 changes: 5 additions & 5 deletions examples/CustomProtoServer/CustomProtoImp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ func (s *CustomProtocolImp) DoClose(ctx context.Context) {
// ParsePackage parse request package
func (s *CustomProtocolImp) ParsePackage(buff []byte) (int, int) {
if len(buff) < 4 {
return 0, transport.PACKAGE_LESS
return 0, transport.PackageLess
}
if len(buff) > 10485760 {
return 0, transport.PACKAGE_ERROR
return 0, transport.PackageError
}
var idx = bytes.Index(buff, []byte("\n"))
if idx > 0 {
return idx + 1, transport.PACKAGE_FULL
return idx + 1, transport.PackageFull
}

return 0, transport.PACKAGE_LESS
return 0, transport.PackageLess
}

// Invoke process request and send response
func (s *CustomProtocolImp) Invoke(ctx context.Context, req []byte) []byte {
fmt.Println("req:", req)
fmt.Print("req:", string(req))
reqMap, err := url.ParseQuery(strings.TrimSpace(string(req)))
if err != nil {
return []byte("ret=-1&msg=invalid_format\n")
Expand Down
10 changes: 5 additions & 5 deletions examples/CustomProtoServer/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ type MyClient struct {
}

func (c *MyClient) Recv(pkg []byte) {
fmt.Println("recv:", string(pkg))
fmt.Print("recv:", string(pkg))
c.recvCount++
}
func (c *MyClient) ParsePackage(buff []byte) (pkgLen, status int) {
if len(buff) < 4 {
return 0, transport.PACKAGE_LESS
return 0, transport.PackageLess
}
if len(buff) > 10485760 {
return 0, transport.PACKAGE_ERROR
return 0, transport.PackageError
}
var idx = bytes.Index(buff, []byte("\n"))
if idx > 0 {
return idx + 1, transport.PACKAGE_FULL
return idx + 1, transport.PackageFull
}

return 0, transport.PACKAGE_LESS
return 0, transport.PackageLess
}

func getMsg(name string, idx int) []byte {
Expand Down
2 changes: 1 addition & 1 deletion examples/CustomProtoServer/debugtool/dumpstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func main() {
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := fmt.Sprintf("Test.CustomProtoServer.CustomProtoObj@tcp -h 127.0.0.1 -p 10015 -t 60000")
app := new(adminf.AdminF)
comm.StringToProxy(obj, app)
Expand Down
2 changes: 1 addition & 1 deletion examples/EchoClientServer/EchoClientServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (imp *EchoClientImp) Sub(a int32, b int32, c *int32) (int32, error) {
}

func main() { //Init servant
comm = tars.NewCommunicator()
comm = tars.GetCommunicator()

// client
log = tars.GetDayLogger("report", 1)
Expand Down
2 changes: 1 addition & 1 deletion examples/EchoClientServer/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := fmt.Sprintf("StressTest.EchoClientServer.EchoClientObj@tcp -h 127.0.0.1 -p 11015 -t 60000")
app := new(StressTest.EchoClient)
comm.StringToProxy(obj, app)
Expand Down
2 changes: 1 addition & 1 deletion examples/EchoTestServer/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := fmt.Sprintf("StressTest.EchoTestServer.EchoTestObj@tcp -h 127.0.0.1 -p 12015 -t 60000")
app := new(StressTest.EchoTest)
comm.StringToProxy(obj, app)
Expand Down
2 changes: 1 addition & 1 deletion examples/PushServer/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func callback(data []byte) {
}

func main() {
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := "TestApp.PushServer.MessageObj@tcp -h 127.0.0.1 -p 10015 -t 60000"
client := push.NewClient(callback)
comm.StringToProxy(obj, client)
Expand Down
2 changes: 1 addition & 1 deletion examples/PushServer/debugtool/dumpstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func main() {
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := "TestApp.PushServer.MessageObj@tcp -h 127.0.0.1 -p 10014 -t 60000"
app := new(adminf.AdminF)
comm.StringToProxy(obj, app)
Expand Down
2 changes: 1 addition & 1 deletion examples/TlsTestServer/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func main() {
tars.ServerConfigPath = "config.conf"
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := fmt.Sprintf("App.TlsTestServer.TlsObj@ssl -h 127.0.0.1 -p 13015 -t 6000000000")
app := new(App.Tls)
comm.StringToProxy(obj, app)
Expand Down
2 changes: 1 addition & 1 deletion examples/TlsTestServer/debugtool/dumpstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func main() {
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := fmt.Sprintf("App.TlsTestServer.TlsObj@tcp -h 127.0.0.1 -p 10014 -t 60000")
app := new(adminf.AdminF)
comm.StringToProxy(obj, app)
Expand Down
2 changes: 1 addition & 1 deletion examples/ZipkinTraceClient/ZipkinTraceClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

var sapp = new(ZipkinTraceApp.ZipkinTrace)
var comm = tars.NewCommunicator()
var comm = tars.GetCommunicator()
var logger = tars.GetLogger("zipkin")

func main() { // Init servant
Expand Down
2 changes: 1 addition & 1 deletion examples/ZipkinTraceClient/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := fmt.Sprintf("ZipkinTraceApp.ZipkinTraceClient.ZipkinClientObj@tcp -h 127.0.0.1 -p 14015 -t 60000")
app := new(ZipkinTraceApp.ZipkinClient)
comm.StringToProxy(obj, app)
Expand Down
2 changes: 1 addition & 1 deletion examples/trace/TarsTraceBackServer/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := fmt.Sprintf("Trace.TarsTraceBackServer.BackendObj@tcp -h 127.0.0.1 -p 20015 -t 60000")
app := new(Trace.Backend)
comm.StringToProxy(obj, app)
Expand Down
2 changes: 1 addition & 1 deletion examples/trace/TarsTraceBackServer/debugtool/dumpstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func main() {
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := fmt.Sprintf("Trace.TarsTraceBackServer.BackendObj@tcp -h 127.0.0.1 -p 10014 -t 60000")
app := new(adminf.AdminF)
comm.StringToProxy(obj, app)
Expand Down
2 changes: 1 addition & 1 deletion examples/trace/TarsTraceFrontServer/Frontend_imp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type FrontendImp struct {
// Init servant init
func (imp *FrontendImp) Init() error {
//initialize servant here:
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := fmt.Sprintf("Trace.TarsTraceBackServer.BackendObj@tcp -h 127.0.0.1 -p 20015 -t 60000")
app := new(Trace.Backend)
comm.StringToProxy(obj, app)
Expand Down
2 changes: 1 addition & 1 deletion examples/trace/TarsTraceFrontServer/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func main() {
tars.ServerConfigPath = "config.conf"
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := fmt.Sprintf("Trace.TarsTraceFrontServer.FrontendObj@tcp -h 127.0.0.1 -p 10015 -t 60000")
app := new(Trace.Frontend)
comm.StringToProxy(obj, app)
Expand Down
2 changes: 1 addition & 1 deletion examples/trace/TarsTraceFrontServer/debugtool/dumpstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func main() {
comm := tars.NewCommunicator()
comm := tars.GetCommunicator()
obj := fmt.Sprintf("Trace.TarsTraceFrontServer.FrontendObj@tcp -h 127.0.0.1 -p 10014 -t 60000")
app := new(adminf.AdminF)
comm.StringToProxy(obj, app)
Expand Down

0 comments on commit d254aa8

Please sign in to comment.