Esempio n. 1
0
func RPCServer(w http.ResponseWriter, req *http.Request) {
	h, buf, err := w.(http.Hijacker).Hijack()
	if err != nil {
		log.Print("ERR: ", err)
	}
	connected := "200 Connected to JSON-RPC"
	io.WriteString(h, "HTTP/1.0 "+connected+"\n\n")
	log.Print("Serving")
	codec := jsonrpc.NewServerCodec(combo{h, buf})
	rpc.ServeRequest(codec)
	h.Close()
}
Esempio n. 2
0
func main() {
	ta := &testApp{"fooname"}
	rpc.Register(ta)
	l, err := net.Listen("tcp", listenport)
	if err != nil {
		log.Exit("Listen error: ", err)
	} else {
		log.Println("Listening: ", l)
	}
	a := "foo"
	var c string
	ta.PrintStuff(&a, &c)
	log.Println(c)
	for conn, err := l.Accept(); err == nil; conn, err = l.Accept() {
		log.Println(conn)
		go rpc.ServeCodec(jsonrpc.NewServerCodec(conn))
	}
	log.Exit("Error: ", err)
}