Beispiel #1
0
// Serve provides the server for reverse RPC calls.
// TODO allow for parallel execution and timout of calls.
func Serve(endpoint, name string) {
	conn := tgorpc.Dial(endpoint)
	for {
		var i int
		var cmd rrpcclient.Call
		//log.Println("DEBUG send Ping")
		err := conn.Call(name+".Ping", i, &cmd)
		//log.Printf("DEBUG rRPCserver Ping reply cmd=%#v\n", cmd)
		if err != nil {
			log.Printf("rRPCserver Ping Error=%s\ncmd=%#v\n", err.Error(), cmd)
		} else {
			if cmd.Valid {
				cmd.Reply, cmd.ErrorMsg = tgoremote.CallFuncDirect(
					cmd.ServiceMethod,
					cmd.Args,
					cmd.Reply,
				)
				err := conn.Call(name+".Pong", cmd, &i)
				if err != nil {
					log.Println("Pong " + err.Error())
				}
			} else {
				//log.Println("DEBUG Ping invalid reply")
			}
		}
		runtime.Gosched()
	}
}
Beispiel #2
0
func main() {
	haxegoruntime.BrowserMain(func() {
		endpt := "http://localhost:8088/_haxeRPC_"

		conn := tgorpc.Dial(endpt)
		var tfooRes int
		err := conn.Call("TfooBase.Add", Tfoo{A: 1, B: 2}, &tfooRes)
		fmt.Println("tfoo:", tfooRes, err)
		var tbarRes string
		err = conn.Call("TbarBase.Join", Tbar{"it", "works", "!"}, &tbarRes)
		fmt.Println("tbar:", tbarRes, err)
		var tdoodahRes []byte
		err = conn.Call("TdoodahBase.Upper",
			Tdoodah{[]byte("The 世界 is my oyster!\n")}, &tdoodahRes)
		fmt.Println("tdoodah:", string(tdoodahRes), err)
		var tdoodahResBad []byte
		err = conn.Call("TdoodahBase.Upper",
			"The 世界 is my whelk!\n", &tdoodahResBad)
		fmt.Println("tdoodah bad call:", string(tdoodahResBad), err)

		var f Float
		tgoremote.Register(f)
		rrpcserver.Serve(endpt, "_RRPC_")

	}, 10 /* ms between each wake-up */, 10000 /* max scheduler runs per wake-up */)
}