Created
June 5, 2013 07:22
-
-
Save grafov/5712165 to your computer and use it in GitHub Desktop.
golang sample of json/rpc over websocket
This file contains hidden or 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 ( | |
"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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this close the connection once the RPC call is executed ?