Created
April 25, 2013 23:27
-
-
Save gmile/5464053 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, ®ion, nil) | |
<-div_call.Done | |
println(region.X, region.Y) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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