mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 04:22:22 +00:00
30 lines
399 B
Go
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()
|
|
}
|
|
}
|