// ServeEchoService serves the given EchoService implementation on conn. func ServeEchoService(conn io.ReadWriteCloser, x EchoService) error { srv := rpc.NewServer() if err := srv.RegisterName("EchoService", x); err != nil { return err } srv.ServeCodec(protorpc.NewServerCodec(conn)) return nil }
// ListenAndServeEchoService listen announces on the local network address laddr // and serves the given EchoService implementation. func ListenAndServeEchoService(network, addr string, x EchoService) error { clients, err := net.Listen(network, addr) if err != nil { return err } srv := rpc.NewServer() if err := srv.RegisterName("EchoService", x); err != nil { return err } for { conn, err := clients.Accept() if err != nil { return err } go srv.ServeCodec(protorpc.NewServerCodec(conn)) } panic("unreachable") }
func listenAndServeArithAndEchoService(network, addr string) error { clients, err := net.Listen(network, addr) if err != nil { return err } srv := rpc.NewServer() if err := RegisterArithService(srv, new(Arith)); err != nil { return err } if err := RegisterEchoService(srv, new(Echo)); err != nil { return err } for { conn, err := clients.Accept() if err != nil { return err } go srv.ServeCodec(protorpc.NewServerCodec(conn)) } panic("unreachable") }
func main() { ln, err := net.Listen("tcp", "127.0.0.1:1234") if err != nil { log.Fatalln(err) } srv := rpc.NewServer() if err := service.RegisterArithService(srv, new(Arith)); err != nil { log.Fatalln(err) } if err := service.RegisterEchoService(srv, new(Echo)); err != nil { log.Fatalln(err) } for { conn, err := ln.Accept() if err != nil { log.Fatalln(err) } go srv.ServeCodec(protorpc.NewServerCodec(conn)) } panic("unreachable") }