Skip to content

Instantly share code, notes, and snippets.

@grafov
Created June 5, 2013 07:22
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save grafov/5712165 to your computer and use it in GitHub Desktop.
Save grafov/5712165 to your computer and use it in GitHub Desktop.
golang sample of json/rpc over websocket
package main
import (
"code.google.com/p/go.net/websocket"
//"github.com/garyburd/go-websocket/websocket"
//"github.com/zhangpeihao/gowebsocket"
"net/http"
"net/rpc"
"net/rpc/jsonrpc"
)
type Args struct {
A int
B int
}
type Arith int
func (t *Arith) Multiply(args *Args, reply *int) error {
*reply = args.A * args.B
return nil
}
func main() {
rpc.Register(new(Arith))
http.Handle("/conn", websocket.Handler(serve))
http.ListenAndServe("localhost:7000", nil)
}
func serve(ws *websocket.Conn) {
jsonrpc.ServeConn(ws)
}
@wiless
Copy link

wiless commented Nov 20, 2014

Does this close the connection once the RPC call is executed ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment