Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chenchao dev #424

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions examples/TarsPushServer/client/DemoClient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package main

import (
"TarPushServer/demo"
"fmt"
"github.com/TarsCloud/TarsGo/tars"
"time"
)

type Callback struct {
start int64
cost int64
count int64
}

func (c *Callback) Push_Callback(msg *string, opt ...map[string]string) {
/* if c.count == 0 {
c.start = time.Now().UnixMicro()
}
c.count++
if c.count == 500000 {
c.cost = time.Now().UnixMicro() - c.start
fmt.Printf("cost--->%vus\n", c.cost)
}*/

//if c.start == 0 {
// c.start = time.Now().UnixMicro()
//} else {
// c.cost = time.Now().UnixMicro() - c.start
//}
//fmt.Printf("cost--->%vus|Push---->:%s======%v\n", c.cost, *msg, opt)
fmt.Printf("%v|Push---->:%s======%v\n", time.Now().UnixMilli(), *msg, opt)
}

func (c Callback) Push_ExceptionCallback(err error) {
panic("implement me")
}

func (c Callback) Reg_Callback(rsp *demo.RegRsp, opt ...map[string]string) {
//TODO implement me
panic("implement me")
}

func (c Callback) Reg_ExceptionCallback(err error) {
//TODO implement me
panic("implement me")
}

func main() {
com := tars.GetCommunicator()
obj := "Base.DemoServer.DemoObj@tcp -h 127.0.0.1 -p 8888 -t 60000"
prx := &demo.DemoObj{}
com.StringToProxy(obj, prx)
prx.SetOnConnectCallback(func(s string) {
fmt.Println("<-----------onConnect--------->")
})
prx.SetOnCloseCallback(func(s string) {
fmt.Println("<-----------onClose----------->")
})
TarsCb := new(Callback)
prx.SetTarsCallback(TarsCb)
go func() {
ticker := time.NewTicker(time.Second * 10)
defer ticker.Stop()
for {
select {
case <-ticker.C:
prx.TarsPing()
}
}
}()
{
req := &demo.RegReq{Msg: "reg"}
rsp := &demo.RegRsp{}
prx.Reg(req, rsp)
}
for true {
time.Sleep(time.Second * 10)
}
}
18 changes: 18 additions & 0 deletions examples/TarsPushServer/demo.tars
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module demo
{
struct RegReq
{
0 optional string msg;
};

struct RegRsp
{
0 optional string msg;
};

interface DemoObj
{
void Push(out string msg);
void Reg(RegReq req, out RegRsp rsp);
};
};
Loading