Я пробую связь JSON-RPC между php и go.
Сервер GO из этого примера https://golang.org/pkg/net/rpc/
package main
import (
"errors"
"net/rpc"
"net"
"log"
"net/http"
)
type Args struct {
A, B int
}
type Quotient struct {
Quo, Rem int
}
type Arith int
func (t *Arith) Multiply(args *Args, reply *int) error {
*reply = args.A * args.B
return nil
}
func (t *Arith) Divide(args *Args, quo *Quotient) error {
if args.B == 0 {
return errors.New("divide by zero")
}
quo.Quo = args.A / args.B
quo.Rem = args.A % args.B
return nil
}
func main() {
arith := new(Arith)
rpc.Register(arith)
rpc.HandleHTTP()
l, e := net.Listen("tcp", ":4444")
if e != nil {
log.Fatal("listen error:", e)
}
// go http.Serve(l, nil)
err:= http.Serve(l, nil)
if err != nil {
log.Fatalf("Error serving: %s", err)
}
}
и php клиент из примера этого репозитория https://github.com/ptcx/jsonrpc-client:
require 'vendor/autoload.php';
$client = new JRClient\Client('tcp', '127.0.0.1:4444');
sleep(5);
$result = $client->call('Arith.Multiply', ['A' => 3, "B" => 4], 1000);
if ($result['error']) {
echo $result['errorMsg'] . "\n";
} else {
var_dump($result['data']);
}
Bur final У меня ошибка: HTTP / 1.1 400 Bad Request
Я пытался также написать sleep(5)
после подключения php, но безрезультатно? Также я попытался изменить с true
на false
на функцию stream_set_blocking($this->sockfp, false)
https://github.com/ptcx/jsonrpc-client/blob/master/src/Connection/TcpConnection.php#L69 - безрезультатно.
Я тред пишу GO клиент - он работает без проблем.
Помогите мне пожалуйста с моим php клиентом