- 🔭 I’m currently working on game company.
- ⚡ Golang/Python/C/C++/C#.
- 📫 How to reach me: [email protected]
- 🍻 Guangzhou,China
trainking / trainking.github.io Goto Github PK
View Code? Open in Web Editor NEWblog
blog
func main() {
var client *arpc.Client
var err error
client, err = arpc.NewClient(dialer)
if err != nil {
log.Fatalf("NewClient failed: %v", err)
}
defer client.Stop()
request := hello.Request{X: 10, Y: 20}
str := ""
client.CallAsync("/gg", &request, func(ctx *arpc.Context) {
ctx.Bind(&str)
log.Printf("Call /gg Response: %v", str)
}, time.Second*3)
// var pClient *arpc.Client
// pClient, err = arpc.NewClient(dialer)
// if err != nil {
// log.Fatalf("NewClient failed: %v", err)
// }
response := hello.Response{}
err = client.CallWith(context.Background(), "/echo", &request, &response)
var rr map[string]interface{} = response.List[0].(map[string]interface{})
if err != nil {
log.Fatalf("Call /echo failed: %v", err)
} else {
log.Printf("Call /echo Response: %v", rr)
}
time.Sleep(time.Second * 10)
}
arpc中同一个*arpc.Clent
使用callAsync
和callWIth
,异步请求也会阻塞其他请求。
因为,同一个*arpc.Client
必须等待结果,他们内部调用的是同一个client.newRequestMessage
函数,发送请求。不一样的是异步请求调用之后,进入等待结果,其他代码可以执行,但是在结果到来之前,这个*arpc.Client
不能再发送其他请求。
因此,arpc最好使用一个请求新建client的方式,避免这种阻塞。
arpc的异步请求需要在服务端设置,才能作为真正的异步请求
async := true
handler.Handle("/gg", func(ctx *arpc.Context) {
time.Sleep(time.Second * 10)
ctx.Write("ppte")
}, async)
访问远程服务,需要配置配置文件
#bind 127.0.0.1
bind 0.0.0.0
重启服务即可。
用命令查看是否生效:
> ps -ef | grep redis
redis 5346 1 0 Dec19 ? 00:00:30 /usr/local/redis/bin/redis-serve r 0.0.0.0:6379
root 16172 16062 0 09:12 pts/0 00:00:00 grep --color redis
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.