Hprose使用说明 · Hexo

Hprose使用说明 · Hexo

简介Hprose(High Performance Remote Object Service Engine)是一款先进的轻量级、跨语言、跨平台、无侵入式、高性能动态远程对象调用引擎库。它不仅简单易用,而且功能强大。 你无需专门学习,只需看上几眼,就能用它轻松构建分布式应用系统。

使用手册案例(php)安装

使用composer require hprose/hprose如果你正在使用 composer 管理你的项目,那么你不需要做任何特别处理。只要在 composer.json 中的 require 段添加了对 hprose/hprose 的引用就可以了。如果你需要 swoole 支持,添加 hprose/hprose-swoole 就可以了。然后在代码中这样引用

服务端123456789101112131415addFunction('hello');$server->start();

客户端1234use Hprose\Client;$client=Client::create('http://localhost/',false);echo $client->hello("World");

案例(go)安装123go get github.com/gorilla/websocketgo get github.com/valyala/fasthttpgo get github.com/hprose/hprose-golang

使用服务端12345678910111213141516package mainimport( "net/http" "github.com/hprose/hprose-golang/rpc" )func hello(name string) string { return "Hello" + name + "!"}func main() { service := rpc.NewHTTPService() service.AddFunction("hello", hello, rpc.Options{}) http.ListenAndServer(":8080",service)}

客户端123456789101112131415161718192021package mainimport ( "fmt" "github.com/hprose/hprose-golang/rpc" )type Stub struct { Hello func(string) (string, error) AsyncHello func(func(string, error),string) `name:"hello"`}func main() { client := rpc.NewClient("http://127.0.0.1:8080/") var stub *Stub client.UseService(&stub) stub.AsyncHello(func(result string,err error) { fmt.Println(result, error) },"async world") fmt.Println(stub.Hello("world"))}

相关推荐

4、穿越火线地狱火怎么获得

4、穿越火线地狱火怎么获得

📅 07-07 👁️ 6684
耐克鞋子可以穿多久

耐克鞋子可以穿多久

📅 07-06 👁️ 6014
散光度数多少算高

散光度数多少算高

📅 07-16 👁️ 976
React 入门 - 学习 Web 开发

React 入门 - 学习 Web 开发

📅 07-10 👁️ 7418