server

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2021 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accept

func Accept(l net.Listener)

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

func Register

func Register(rcvr interface{}) error

defalut server register

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

represents an RPC server

func NewServer

func NewServer() *Server

construct func and retrun *Server

func (*Server) Accept

func (server *Server) Accept(l net.Listener)

Accept func accepts connections from clients

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) Register

func (server *Server) Register(rcvr interface{}) error

Register allow rcvr dup method to server.serviceMethodMap

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL