Files
ppgo_job/agent/server/service.go
2019-07-03 22:31:27 +08:00

39 lines
804 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/************************************************************
** @Description: service
** @Author: george hao
** @Date: 2019-06-26 15:27
** @Last Modified by: george hao
** @Last Modified time: 2019-06-26 15:27
*************************************************************/
package server
import (
"net"
"net/rpc"
"net/rpc/jsonrpc"
"strconv"
)
//初始化路由
func init() {
rpc.RegisterName("RpcTask", new(RpcTask))
rpc.RegisterName("HeartBeat", new(RpcTask))
}
func RpcRun() error {
listener, err := net.Listen("tcp", ":"+strconv.Itoa(C.TcpPort))
if err != nil {
return err
}
for {
conn, err := listener.Accept()
if err != nil {
return err
}
//注意ServerCodec是个方法不是接口
go rpc.ServeCodec(jsonrpc.NewServerCodec(conn))
//go rpc.ServeConn(conn)
}
}