Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Accept ¶
defaultServer Accept func use like : lis, _ := net.Listen("tcp", ":9999")
geerpc.Accept(lis)
func HandleHTTP ¶
func HandleHTTP()
HandleHTTP is a convenient approach for default server to register HTTP handlers
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
represents an RPC server
func (*Server) HandleHTTP ¶
func (s *Server) HandleHTTP()
HandleHTTP registers an HTTP handler for RPC messages on rpcPath. It is still necessary to invoke http.Serve(), typically in a go statement.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements an http.Handler that answers RPC requests.
func (*Server) ServerConn ¶
func (server *Server) ServerConn(conn io.ReadWriteCloser)
一般来说,涉及协议协商的这部分信息,需要设计固定的字节来传输的。但是为了实现上更简单, GeeRPC 客户端固定采用 JSON 编码 Option,后续的 header 和 body 的编码方式由 Option 中的 CodeType 指定, 服务端首先使用 JSON 解码 Option,然后通过 Option 的 CodeType 解码剩余的内容。即报文将以这样的形式发送: | Option{MagicNumber: xxx, CodecType: xxx} | Header{ServiceMethod ...} | Body interface{} | | <------ 固定 JSON 编码 ------> | <------- 编码方式由 CodeType 决定 ------->|
goroutine to solve connections