1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-24 20:47:11 +00:00
2018-12-16 12:40:54 +08:00

30 lines
399 B
Go

package main
import (
"net"
"net/rpc"
"time"
)
type HelloService struct{}
func (p *HelloService) Hello(request string, reply *string) error {
*reply = "hello:" + request
return nil
}
func main() {
rpc.Register(new(HelloService))
for {
conn, _ := net.Dial("tcp", "localhost:1234")
if conn == nil {
time.Sleep(time.Second)
continue
}
rpc.ServeConn(conn)
conn.Close()
}
}