android有关jsonrpc的使用,谁用过,能不能加Q指导下?

android有关jsonrpc的使用,谁用过,能不能加Q指导下?用XMLRPC也可以,本人完全没看懂网上的例子

1个回答

skyunicorn
小麟 早看过了,下面都有我的评论,写的不明白
大约 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Python+OpenCV计算机视觉

Python+OpenCV计算机视觉

使用curl调用golang调用jsonrpc

<div class="post-text" itemprop="text"> <p>I've "hello world" rpc service written on golang. It works fine and go jsonrpc client is working. But I need to send request with curl and this example doesn't work:</p> <pre><code>curl \ -X POST \ -H "Content-Type: application/json" \ -d '{"id": 1, "method": "Test.Say", "params": [{"greet": "world"}]}' \ http://localhost:1999/_goRPC_ </code></pre> <p>Go accept connection but produce absolutely no result:</p> <pre><code>curl: (52) Empty reply from server </code></pre> <p>Here my go code:</p> <pre><code>package main import ( "log" "os" "time" "net" "net/rpc" "net/rpc/jsonrpc" ) // RPC Api structure type Test struct {} // Greet method arguments type GreetArgs struct { Name string } // Grret message accept object with single param Name func (test *Test) Greet(args *GreetArgs, result *string) (error) { *result = "Hello " + args.Name return nil } // Start server with Test instance as a service func startServer(ch chan&lt;- bool, port string) { test := new(Test) server := rpc.NewServer() server.Register(test) listener, err := net.Listen("tcp", ":" + port) if err != nil { log.Fatal("listen error:", err) } defer listener.Close() for { conn, err := listener.Accept() if err != nil { log.Fatal(err) } go server.ServeCodec(jsonrpc.NewServerCodec(conn)) ch &lt;- true } } // Start client and call Test.Greet method func startClient(port string) { conn, err := net.Dial("tcp", ":" + port) if err != nil { panic(err) } defer conn.Close() c := jsonrpc.NewClient(conn) var reply string var args = GreetArgs{"world"} err = c.Call("Test.Greet", args, &amp;reply) if err != nil { log.Fatal("arith error:", err) } log.Println("Result: ", reply) } func main() { if len(os.Args) &lt; 2 { log.Fatal("port not specified") } port := os.Args[1] ch := make(chan bool) go startServer(ch, port) time.Sleep(500 * time.Millisecond) go startClient(port) // Produce log message each time connection closes for { &lt;-ch log.Println("Closed") } } </code></pre> </div>

Jsonrpc4j和go的rpc / jsonrpc之间的JSONRPC格式不同

<div class="post-text" itemprop="text"> <p>I was meet a problem when I tried used net/jsonrpc package to build a server and a Java client with jsonrpc4j</p> <p>The problem is jsonrpc4j is when error happen, golang`s method will return error and encoding to json.</p> <p>I got this json object in client</p> <blockquote> <p>{"id": -6028374044949000, "result": null, "error": "some error return message"}</p> </blockquote> <p>This object cast failed in java's json4j.</p> <p><a href="http://www.jsonrpc.org/specification#error_object" rel="nofollow">http://www.jsonrpc.org/specification#error_object</a></p> <p>After I checked the jsonrpc page, it is said the error field MUST a json object with fields [code, message, date], the golang jsonrpc package not meet the require.</p> <p>So I`m confused how to solve this. Change the jsonrpc lib, Just replace the rpc way to thrift/gRpc, Avoid to return error but send error in reply and let Java check the response, Or just edited the json4j or golang's source code ( I'm very horrible about this option)</p> <p>Thanks for watch.</p> </div>

在App Engine中使用rpc / jsonrpc

<div class="post-text" itemprop="text"> <p>I'm confused reading "rpc" and "rpc/jsonrpc" code and docs. We won't listen to a port to serve RPC requests on App Engine, I mean, we won't "start a server", so how it should work?</p> </div>

JSONRPC服务器返回空结果

<div class="post-text" itemprop="text"> <p>I've coded a simple JSONRPC server to test Go's capabilities, but I'm stuck, always getting an empty result, without error and correct id. I've got the following Go code: package main</p> <pre><code>import ( "log" "net" "net/rpc" "net/rpc/jsonrpc" ) type Experiment int func (e *Experiment) Test(i *string, reply *string) error { s := "Hello, " + *i reply = &amp;s log.Println(s, reply) return nil } func main() { exp := new(Experiment) server := rpc.NewServer() server.Register(exp) l, err := net.Listen("tcp", ":1234") if err != nil { log.Fatal("listen error:", err) } for { conn, err := l.Accept() if err != nil { log.Fatal(err) } server.ServeCodec(jsonrpc.NewServerCodec(conn)) } } </code></pre> <p>No matter what I tried, I've always got the following response:</p> <pre><code>{"id":1,"result":"","error":null} </code></pre> <p>Logging shows everything is working as it should in the server.</p> <pre><code>2013/07/17 15:17:13 Hello, Paulo 0xc200090ac0 </code></pre> <p>Any ideas on what's going on? I'm using the latest stable version of Go, v1.1.1</p> <p>Thanks</p> </div>

拨打jsonrpc连接到比特币

<div class="post-text" itemprop="text"> <pre><code>package main import "rpc/jsonrpc" import "fmt" func main() { rc, e := jsonrpc.Dial("tcp", "user:pass@localhost:8332") if e != nil {fmt.Print(e);return;} var blocks float64 rc.Call("getblockcount", "", &amp;blocks) if e != nil {fmt.Print(e); return;} fmt.Print("%f blocks", blocks) } </code></pre> <p>Gives me the following error: <code>dial tcp user:pass@localhost:8332: too many colons in address user:pass@localhost:8332</code></p> <p>How do I authenticate my rpc connection?</p> </div>

golang jsonrpc调用java json rpc

<div class="post-text" itemprop="text"> <p>I was trying to connect golang programs with java programs by json rpc, but ran into some trouble. I use the "net/rpc/jsonrpc" package from golang native packages, and "jsonrpc4j" for java. I use stream mode to create a server in java, because golang's jsonrpc just supports tcp invoke. But it still gets the error response in golang client:</p> <blockquote> <p>err: invalid error map[code:-32602 message:Invalid method parameters]</p> </blockquote> <p>Meanwhile the java server is also encountering error:</p> <blockquote> <p>com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input at [Source: com.googlecode.jsonrpc4j.NoCloseInputStream@385b5b5c; line: 1, column: 1] at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148) at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3747) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3687) at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2202) at com.googlecode.jsonrpc4j.JsonRpcServer.handle(JsonRpcServer.java:224) at com.googlecode.jsonrpc4j.StreamServer$Server.run(StreamServer.java:214) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:744)</p> </blockquote> <p>I don't understand why it does not work, is there any discipline that exists in the jsonrpc protocol that golang can't invoke java or do I just not do it right?</p> </div>

如何在Golang中使用jsonrpc包从服务器向客户端发送嵌套地图?

<div class="post-text" itemprop="text"> <p>I am writing a client server go application which uses yahoo finance api to fetch the real time stock price. I am using jsonrpc package to connect client and server. I am unable to pass a nested map response from server to client. Here is my small snippet from the client file. client.go file</p> <pre><code>var ( reply map[string]map[int]float64 ) c := jsonrpc.NewClient(client) err = c.Call("JSONResponse.GetStockValue", args, &amp;reply) fmt.Println(reply) </code></pre> <p>Server file looks like this:</p> <pre><code>func (j *JSONResponse) GetStockValue(args *ClientRequest, reply *map[string]map[int]float64) error { some piece of code...... nestedMap := make(map[string]map[int]float64) add some values in nested map ..... fmt.Println(nestedMap) *reply = nestedMap return nil } </code></pre> <p>This does not send any response to the client. When i change the nested map to simple map like map[string]int, it correctly works. The nested map is correctly displayed at server but does not get displayed on the client side. The client simply keeps on waiting for the response from the server. It would be very helpful if someone could guide me on why it is not accepting a nested map and working fine for a simple map ?</p> <p>Thanks :)</p> </div>

从网页访问golang http + jsonrpc

<div class="post-text" itemprop="text"> <p>I've used Go's <code>net/rpc</code> and <code>net/rpc/jsonrpc</code> packages a bit to perform connections between Go processes, however I'm wondering if there is a way to connect to an HTTP JSONRPC server using only the server tooling from the standard library (not that I have a problem writing my own, just don't want to do it if I don't have to).</p> <p>This is the basic server setup I have:</p> <pre><code>arith := new(server.Arith) server := rpc.NewServer() server.Register(arith) server.HandleHTTP(rpc.DefaultRPCPath, rpc.DefaultDebugPath) listener, e := net.Listen("tcp", ":4321") if e != nil { log.Fatal("listen error:", e) } defer listener.Close() http.Serve(listener, http.DefaultServeMux) </code></pre> <p>And I'd like to be able to be hitting this from a web page or a simple command line CURL call - just a regular POST.</p> <p>However, this line: <a href="http://golang.org/src/net/rpc/server.go?s=20445:20475#L670" rel="nofollow">http://golang.org/src/net/rpc/server.go?s=20445:20475#L670</a> appears to indicate that it expects an HTTP client to issue a CONNECT and then directly write the JSON RPC request to the stream and receive the reply back the same way. I don't know if this is even possible from a browser, but it certainly is not as common or compatible as a simple POST.</p> <p>Is there a way to start a JSON RPC server that I can just POST to using good ol' XMLHttpRequest ?</p> <p>EDIT: Crap - the above is not even using the jsonrpc stuff - this is probably trying to use Gob, but whatever - the problem is the same - the code in src/net/rpc/server.go is not going to handle POSTs, so this route overall isn't going to work regardless of server codec.</p> </div>

Go中基于HTTP的JSONRPC [重复]

<div class="post-text" itemprop="text"> <div class="question-status question-originals-of-duplicate"> <p>This question already has an answer here:</p> <ul> <li> <a href="/questions/31396924/golang-httpjsonrpc-access-from-web-page" dir="ltr">golang http+jsonrpc access from web page</a> <span class="question-originals-answer-count"> 2 answers </span> </li> </ul> </div> <p>How can I use JSON-RPC over HTTP based on <a href="http://www.jsonrpc.org/historical/json-rpc-over-http.html" rel="nofollow noreferrer">this specification</a> in Go?</p> <p>Go provides JSON-RPC codec in <code>net/rpc/jsonrpc</code> but this codec use network connection as input so you cannot use it with go RPC HTTP handler. I attach sample code that uses TCP for JSON-RPC:</p> <pre><code>func main() { cal := new(Calculator) server := rpc.NewServer() server.Register(cal) listener, e := net.Listen("tcp", ":1234") if e != nil { log.Fatal("listen error:", e) } for { if conn, err := listener.Accept(); err != nil { log.Fatal("accept error: " + err.Error()) } else { log.Printf("new connection established ") go server.ServeCodec(jsonrpc.NewServerCodec(conn)) } } } </code></pre> </div>

js访问不了jsonrpc-cpp开发的应用程序

为什么用js在本地可以访问jsonrpc-cpp应用程序,在别的电脑访问不了json应用程序呢

使用Jjsonrpc4j连接OVSDB报错

使用jsonrpc4j远程调用ovsdb,报错 ``` JsonRpcHttpClient jsonRpcHttpClient = new JsonRpcHttpClient(new URL("http://192.168.1.177:6632")); Map<String, String> headers = new HashMap<>(); headers.put("Accept", "application/json"); headers.put("Content-Type", "application/json"); jsonRpcHttpClient.setHeaders(headers); String result = jsonRpcHttpClient.invoke("list_dbs", null, String.class); System.out.println(result); ``` ![错误](https://img-ask.csdn.net/upload/201811/14/1542187086_883694.png) 求大神帮助解决,谢谢!

Goor中带有Gorilla / rpc的JSON RPC请求

<div class="post-text" itemprop="text"> <p>I'm trying to use the <code>Gorilla/rpc</code> package to set up a RPC to receive a request and reply with a response (obviously).</p> <p>First I'm trying with the example provided with <code>Gorilla/rpc</code></p> <p>Here's my code:</p> <pre><code>type HelloArgs struct { Who string } type HelloReply struct { Message string } type HelloService struct{} func (h *HelloService) Say(r *http.Request, args *HelloArgs, reply *HelloReply) error { reply.Message = "Hello, " + args.Who + "!" return nil } func main() { r := mux.NewRouter() jsonRPC := rpc.NewServer() jsonCodec := json.NewCodec() jsonRPC.RegisterCodec(jsonCodec, "application/json") jsonRPC.RegisterCodec(jsonCodec, "application/json; charset=UTF-8") // For firefox 11 and other browsers which append the charset=UTF-8 jsonRPC.RegisterService(new(HelloService), "") r.Handle("/api", jsonRPC) http.ListenAndServe(":"+port, nil) } </code></pre> <p>I have a couple of issues:</p> <ol> <li><p>I'm not sure how I would set a <code>Access-Control-Allow-Origin</code> header like I normally would on a <code>http.ResponseWriter</code> (with a regular webserver) for cross domain requests, as this doesn't take a <code>http.ResponseWriter</code> as an argument.</p></li> <li><p>What would I actually send to access the <code>HelloService.Say</code> method? I've tried <code>{ method: "HelloService.Say", params:[{Who: "Me"}]}</code> but I get <code>405 (Method Not Allowed)</code> (not sure if this is because I can't make x-domain requests though?)</p></li> </ol> <p>Any insight greatly appreciated.</p> </div>

jsonrpc服务器接受请求的小写方法名称(用于大写注册的服务)

<div class="post-text" itemprop="text"> <p>I'm trying to write a jsonrpc server that will accept requested method names in lower case, eg Arith.multiply, and correctly route them to the corresponding uppercase methed, e.g Arith.Multiply. Is this possible?</p> <p>P.S. It's lightweight clone of production server for testing, the API is fixed, including the lowercase method names, so I can't change requested method names to uppercase.</p> <pre><code>package main import ( "log" "net/http" "github.com/gorilla/mux" "github.com/gorilla/rpc" "github.com/gorilla/rpc/json" ) type Args struct { A, B int } type Arith int type Result int func (t *Arith) Multiply(r *http.Request, args *Args, result *Result) error { log.Printf("Multiplying %d with %d ", args.A, args.B) *result = Result(args.A * args.B) return nil } func main() { s := rpc.NewServer() s.RegisterCodec(json.NewCodec(), "application/json") s.RegisterCodec(json.NewCodec(), "application/json;charset=UTF-8") arith := new(Arith) s.RegisterService(arith, "") r := mux.NewRouter() r.Handle("/rpc", s) http.ListenAndServe(":1234", r) } </code></pre> </div>

通过JSON-RPC调用传递身份验证详细信息

<div class="post-text" itemprop="text"> <p>I haven't been able to find any documentation on this. I need to make JSON-RPC calls to an API that requires (basic) authentication details to be passed, but can't find any way to do this with the standard <code>net/rpc/jsonrpc</code> package. A clipped version of my non-authenticating code is below.</p> <pre><code>var reply string netClient, _ = net.Dial("tcp", "localhost:1234") jsonClient = jsonrpc.NewClient(netClient) jsonClient.Call("someMethod", someArgs, &amp;reply) </code></pre> </div>

转到websocket jsonrpc浏览器连接关闭

<div class="post-text" itemprop="text"> <p>I have a WebSocket JSON-RPC server example that I want to use from a browser. When you access the URL "http:localhost:8080", the browser opens the WebSocket connection properly. But when the browser sends the WebSocket request, the server closes the WebSocket connection. I can't even see a trace of the RPC method being called on the server.</p> <p>However, calling the server from a Go client works perfectly.</p> <p><strong>server.go</strong></p> <pre class="lang-js prettyprint-override"><code>package main import ( "log" "net/http" "net/rpc" "net/rpc/jsonrpc" "github.com/gorilla/websocket" ) type Service struct{} func (t *Service) Echo(req *string, res *string) error { log.Printf("Service.Echo") *res = *req log.Printf("Service.Echo req:%s res:%s", *req, *res) return nil } var upgrader = websocket.Upgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, } func serveWS(w http.ResponseWriter, r *http.Request) { ws, err := upgrader.Upgrade(w, r, nil) defer ws.Close() if err != nil { log.Println(err) return } jsonrpc.ServeConn(ws.UnderlyingConn()) } func main() { rpc.Register(new(Service)) http.Handle("/", http.FileServer(http.Dir("web"))) http.HandleFunc("/ws", serveWS) http.ListenAndServe(":8080", nil) } </code></pre> <p><strong>web/index.html</strong></p> <pre class="lang-js prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; var ws = new WebSocket("ws://localhost:8080/ws"); ws.onopen = function(ev){ alert("open"); } ws.onmessage = function(ev){ alert("message"); } ws.onclose = function(ev){ alert("close"); } function send() { msg = { method: "Service.Echo", params: "hello", id: 0 }; var s = JSON.stringify(msg); alert(s); ws.send(s); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;button onclick='send()'&gt;Send&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>client.go</strong></p> <pre class="lang-js prettyprint-override"><code>package main import ( "log" "net/rpc/jsonrpc" "github.com/gorilla/websocket" ) func main() { ws, _, err := websocket.DefaultDialer.Dial("ws://localhost:8080/ws", nil) if err != nil { log.Fatal("dial:", err) } defer ws.Close() client := jsonrpc.NewClient(ws.UnderlyingConn()) req := "hello" var res string err = client.Call("Service.Echo", &amp;req, &amp;res) if err != nil { log.Fatal("Service.Echo error:", err) } log.Printf("Service.Echo: req:%s res:%s", req, res) } </code></pre> <p>Do you know what the problem could be?</p> <p>Thank you very much.</p> <p>Cheers</p> </div>

大猩猩jsonrpc得到空响应

<div class="post-text" itemprop="text"> <p>Why does my jsonrpc method return an empty response?</p> <pre><code>type Args struct { A, B int } type Response struct { sum int message string } type Arith int func (t *Arith) Add(r *http.Request, args *Args, reply *Response) error { reply.sum = args.A + args.B reply.message = "Do math" // this does not work either //*reply = Response{ // sum : 12, // message : "Do math", //} return nil } </code></pre> <p>Request:</p> <pre><code>{"method":"Arith.Add","params":[{"A": 10, "B":2}], "id": 1} </code></pre> <p>Response:</p> <pre><code>{ "result": {}, "error": null, "id": 1 } </code></pre> <p>However, if I set the type of <code>reply</code> to <code>*string</code>, then this will work fine:</p> <pre><code>*reply = "Responding with strings works" </code></pre> <p>Response:</p> <pre><code>{ "result": "Responding with strings works", "error": null, "id": 1 } </code></pre> <p>I'm using <a href="http://www.gorillatoolkit.org/pkg/rpc" rel="nofollow">http://www.gorillatoolkit.org/pkg/rpc</a>.</p> </div>

比特币PHP JSONRPC权限被拒绝

<div class="post-text" itemprop="text"> <p>After reading <a href="https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)#PHP" rel="nofollow">https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)#PHP</a> and also other tutorials, i haven't gotten it to work. All the JSON RPC libraries i use return the same error:</p> <blockquote> <p>4.81.94:8332/): failed to open stream: Permission denied in /var/www/html/v2/jsonRPCClient.php on line 132</p> </blockquote> <p>I also tried easybitcoin.php found on Github that one shows nothing but a blank page.</p> <p>HOWEVER, when i run the command in SSH, it works perfectly.</p> <blockquote> <p>bitcoin-cli getinfo</p> </blockquote> <p>works in SSH and also</p> <blockquote> <p>php bt.php</p> </blockquote> <p>also works but when i run this in browser like <a href="http://ipaddress/bt.php" rel="nofollow">http://ipaddress/bt.php</a> all i get is a blank page(Using easybitcoin.php) or Permission Denied(Using JsonRPC) </p> <p>Any ideas? </p> </div>

JSON RPC客户端Go

<div class="post-text" itemprop="text"> <p>I have a python server serving response through JSON-RPC. Here is a sample response from the server.</p> <pre><code>'{"jsonrpc": "2.0", "result": "Peer 1: local 10.10.0.2 remote 10.10.0.1 state CONNECT\ Peer 2: local 10.10.0.18 remote 10.10.0.17 state ESTABLISHED\ Peer 3: local 10.10.0.10 remote 10.10.0.9 state ESTABLISHED", "id": "839732f9-cf36-46ff-8b9b-6120250d9ce5"}' </code></pre> <p>Here is the request I need to send to the server: </p> <pre><code>'{"method":"echo","jsonrpc":"2.0","params":["test_params"],"id":"839732f9-cf36-46ff-8b9b-6120250d9ce5"}' </code></pre> <p>Here is my client with go language:</p> <pre><code>package main import ( "fmt" "log" "net" "net/rpc/jsonrpc" ) type Args struct { jsonrpc, id string } func main() { conn, err := net.Dial("tcp", "11.21.22.221:8080") if err != nil { panic(err) } defer conn.Close() args := Args{"2.0", "d87198f0-af92-49f8-9a7d-ab8bed5c4d17"} var reply string c := jsonrpc.NewClient(conn) err = c.Call("echo", args, &amp;reply) if err != nil { log.Fatal("error:", err) } fmt.Printf("Response: %d", reply) } </code></pre> <p>But, when I run this client, it is not sending anything in the params. Instead it is sending empty params like this:</p> <pre><code>'{"method":"echo","params":[{}],"id":0} </code></pre> <p>Can somebody help me telling what mistake I am making? I am a newbie to go language.</p> <p>Thanks.</p> </div>

JSON-RPC,“无法解组对象”

<div class="post-text" itemprop="text"> <p>I am trying to learn how JSON-RPC works and am testing it in Go language (golang). The Go program works fine. It does what it should do. But when I try to make a raw request via telnet, it gives an error.</p> <p>The working and super simple JSON-RPC server is described here:</p> <pre><code> // rpc_json_server.go package main import ( "log" "net" "net/http" "net/rpc" "net/rpc/jsonrpc" ) //------------------------------------------------------------------------------ // Types //------------------------------------------------------------------------------ type Arithmetic int // Used as RPC Service called 'Arithmetic' type Arguments struct { A int B int } type Result int //------------------------------------------------------------------------------ // Methods //------------------------------------------------------------------------------ func (t *Arithmetic) Multiply(args *Arguments, res *Result) error { *res = Result(args.A * args.B) return nil } //------------------------------------------------------------------------------ func main() { var srv *rpc.Server var err error var arith *Arithmetic var listener net.Listener var codec rpc.ServerCodec var srv_conntype, srv_host, srv_port, srv_addr, srv_path string var srv_debugPath string var connection net.Conn srv_conntype = "tcp" srv_host = "0.0.0.0" srv_port = "3000" srv_addr = srv_host + ":" + srv_port srv_path = "/" srv_debugPath = "/debug" // Create Server, register Service srv = rpc.NewServer() arith = new(Arithmetic) err = srv.Register(arith) if err != nil { log.Fatalf("Error. Service Format is not correct. %s ", err) //dbg } // Handle, listen srv.HandleHTTP(srv_path, srv_debugPath) listener, err = net.Listen(srv_conntype, srv_addr) if err != nil { log.Fatalf("Error. Can not listen on %s. %s ", srv_addr, err) //dbg } log.Printf("Started RPC Handler at %s. ", srv_addr) //dbg // Serve for { connection, err = listener.Accept() if err != nil { log.Fatal(err) } codec = jsonrpc.NewServerCodec(connection) go srv.ServeCodec(codec) } err = http.Serve(listener, nil) if err != nil { log.Fatalf("Serve Error. %s ", err) //dbg } } //------------------------------------------------------------------------------ </code></pre> <p>The working and super simple JSON-RPC client's code is following:</p> <pre><code> // rpc_json_client.go package main import ( "fmt" "log" "net" "net/rpc" "net/rpc/jsonrpc" ) //------------------------------------------------------------------------------ // Types //------------------------------------------------------------------------------ type Arithmetic int // Used as RPC Service called 'Arithmetic' type Arguments struct { A int B int } type Result int //------------------------------------------------------------------------------ // Methods //------------------------------------------------------------------------------ func main() { var err error var srv_conntype, srv_host, srv_port, srv_addr string //var srv_path string var client *rpc.Client var args Arguments var result Result var serviceName, methodName, funcName string var connection net.Conn srv_conntype = "tcp" srv_host = "0.0.0.0" srv_port = "3000" srv_addr = srv_host + ":" + srv_port //srv_path = "/" // Connect to RPC Server connection, err = net.Dial(srv_conntype, srv_addr) if err != nil { log.Fatalf("Error. Can not connect to %s. %s ", srv_addr, err) //dbg } defer connection.Close() // Client client = jsonrpc.NewClient(connection) // Prepare Call serviceName = "Arithmetic" methodName = "Multiply" funcName = serviceName + "." + methodName args.A = 7 args.B = 8 // Call remote Procedure err = client.Call(funcName, args, &amp;result) if err != nil { log.Fatalf("Error. %s ", err) //dbg } // Show Results fmt.Printf("[%d; %d] -&gt; [%d]. ", args.A, args.B, result) //dbg } </code></pre> <p>Once again. This golang program works fine.</p> <p>But the next thing I cannot understand.</p> <pre><code> telnet localhost 3000 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. { "jsonrpc":"2.0", "method":"Arithmetic.Multiply", "params": { "A": 5, "B": 6 }, "id":1 } {"id":1,"result":null,"error":"json: cannot unmarshal object into Go value of type [1]interface {}"} </code></pre> <p>Please, give me some advice or the reason for such an error. What is wrong in the raw request?</p> <p>Thanks in advance!</p> </div>

2019 Python开发者日-培训

2019 Python开发者日-培训

150讲轻松搞定Python网络爬虫

150讲轻松搞定Python网络爬虫

设计模式(JAVA语言实现)--20种设计模式附带源码

设计模式(JAVA语言实现)--20种设计模式附带源码

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

java后台+微信小程序 实现完整的点餐系统

java后台+微信小程序 实现完整的点餐系统

三个项目玩转深度学习(附1G源码)

三个项目玩转深度学习(附1G源码)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

2019 AI开发者大会

2019 AI开发者大会

玩转Linux:常用命令实例指南

玩转Linux:常用命令实例指南

一学即懂的计算机视觉(第一季)

一学即懂的计算机视觉(第一季)

4小时玩转微信小程序——基础入门与微信支付实战

4小时玩转微信小程序——基础入门与微信支付实战

Git 实用技巧

Git 实用技巧

Python数据清洗实战入门

Python数据清洗实战入门

使用TensorFlow+keras快速构建图像分类模型

使用TensorFlow+keras快速构建图像分类模型

实用主义学Python(小白也容易上手的Python实用案例)

实用主义学Python(小白也容易上手的Python实用案例)

程序员的算法通关课:知己知彼(第一季)

程序员的算法通关课:知己知彼(第一季)

MySQL数据库从入门到实战应用

MySQL数据库从入门到实战应用

机器学习初学者必会的案例精讲

机器学习初学者必会的案例精讲

手把手实现Java图书管理系统(附源码)

手把手实现Java图书管理系统(附源码)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

.net core快速开发框架

.net core快速开发框架

玩转Python-Python3基础入门

玩转Python-Python3基础入门

Python数据挖掘简易入门

Python数据挖掘简易入门

微信公众平台开发入门

微信公众平台开发入门

程序员的兼职技能课

程序员的兼职技能课

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

HoloLens2开发入门教程

HoloLens2开发入门教程

微信小程序开发实战

微信小程序开发实战

Java8零基础入门视频教程

Java8零基础入门视频教程

相关热词 c#跨线程停止timer c#批量写入sql数据库 c# 自动安装浏览器 c#语言基础考试题 c# 偏移量打印是什么 c# 绘制曲线图 c#框体中的退出函数 c# 按钮透明背景 c# idl 混编出错 c#在位置0处没有任何行
立即提问