Skip to content

Instantly share code, notes, and snippets.

@jasonmoo
Created October 15, 2012 18:33
Show Gist options
  • Save jasonmoo/3894210 to your computer and use it in GitHub Desktop.
Save jasonmoo/3894210 to your computer and use it in GitHub Desktop.
Go rpc server over tcp
package main
import (
"log"
"net"
"net/rpc"
)
type System int
func (System) Ping(message, reply *string) error {
if *message == "ping" {
*reply = "pong"
} else {
*reply = "wut?"
}
return nil
}
func main() {
sys := new(System)
server := rpc.NewServer()
server.Register(sys)
l, err := net.Listen("tcp", ":8080")
if err != nil {
log.Fatal("listen error:", err)
}
server.Accept(l)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment