Skip to content

Instantly share code, notes, and snippets.

@kisielk
Created August 1, 2012 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kisielk/3231027 to your computer and use it in GitHub Desktop.
Save kisielk/3231027 to your computer and use it in GitHub Desktop.
Server in golang
#!/usr/bin/env python
import jsonrpclib
s = jsonrpclib.Server('http://localhost:1234/rpc')
s.Say('Kamil')
package main
import (
"code.google.com/p/gorilla/rpc"
"code.google.com/p/gorilla/rpc/json"
"net/http"
)
type HelloArgs struct {
Who string
}
type HelloReply struct {
Message string
}
type HelloService struct{}
func (h *HelloService) Say(r *http.Request, args *HelloArgs, reply *HelloReply) error {
reply.Message = "Hello, " + args.Who + "!"
return nil
}
func main() {
s := rpc.NewServer()
s.RegisterCodec(json.NewCodec(), "application/json-rpc")
s.RegisterCodec(json.NewCodec(), "application/x-www-form-urlencoded")
s.RegisterService(new(HelloService), "")
http.Handle("/rpc", s)
http.ListenAndServe(":1234", nil)
}
File "<stdin>", line 1, in <module>
File "/Network/Cluster/home/kamil/.virtualenvs/jsonrpc/lib/python2.6/site-packages/jsonrpclib/jsonrpc.py", line 274, in __call__
return self.__send(self.__name, args)
File "/Network/Cluster/home/kamil/.virtualenvs/jsonrpc/lib/python2.6/site-packages/jsonrpclib/jsonrpc.py", line 224, in _request
response = self._run_request(request)
File "/Network/Cluster/home/kamil/.virtualenvs/jsonrpc/lib/python2.6/site-packages/jsonrpclib/jsonrpc.py", line 242, in _run_request
verbose=self.__verbose
File "/opt/zymeworks/platform/4.0.22/lib/python2.6/xmlrpclib.py", line 1243, in request
headers
xmlrpclib.ProtocolError: <ProtocolError for localhost:1234/rpc: 400 Bad Request>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment