Skip to content

Instantly share code, notes, and snippets.

@gmile
Created April 25, 2013 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gmile/5464053 to your computer and use it in GitHub Desktop.
Save gmile/5464053 to your computer and use it in GitHub Desktop.
package main
import "net/rpc"
type Region struct {
X, Y int
}
func main() {
client, _ := rpc.Dial("tcp", ":8080")
region := Region{0,0}
div_call := client.Go("MyRegionServer.GetRegion", 1, &region, nil)
<-div_call.Done
println(region.X, region.Y)
}
package main
import "net"
import "net/rpc"
type Region struct {
X, Y int
}
type MyRegionServer int
func (s *MyRegionServer) GetRegion(id *int, reply *Region) error {
println("Someone want's a region with id", *id)
found_region := Region{10,20}
reply = &found_region
println("Let's give him a region", reply.X, reply.Y)
return nil
}
func main() {
listener, _ := net.Listen("tcp", ":8080")
rpc_server := rpc.NewServer()
rpc_server.Register( new(MyRegionServer) )
for {
rpc_server.Accept(listener)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment