doutizha7526 2014-03-14 17:43
浏览 512
已采纳

是什么原因导致客户端。调用rpc在Go(golang)中返回错误?

When does c.Call(...) return a non-nil value?

Can the c.Call(...) only return an error when a network failure occurs (packets lost or timed out or something along those lines)?

If the server srv crashes, will c.Call(...) return an error?

Specifically, can c.Call(...) return an error AFTER the request successfully arrived at srv but BEFORE the rpcname handler function returns?

import (
    "net/rpc"
    "fmt"
)

func call(srv string, rpcname string, args interface{}, reply interface{}) bool {
    c, errx := rpc.Dial("unix", srv)
    if errx != nil {
        return false
    }
    defer c.Close()

    err := c.Call(rpcname, args, reply)
    if err == nil {
        return true
    }

    fmt.Println(err)
    return false
}
  • 写回答

1条回答 默认 最新

  • dstjh46606 2014-03-15 05:23
    关注

    If you have a look at client.go in the source code for net/rpc you'll see quite a few lines where call.Error is set. These should show you all of the conditions under which a Call will return an error.

    Many of them are generated upon encountering errors from ClientCodec.WriteRequest and ClientCodec.ReadResponseBody. See the ClientCodec docs for more details.

    There are also a couple of possible errors for encountering unexpected EOF, and ErrShutdown when the client is closing.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 adb连接不到手机是怎么回事?
  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目