Python Usage
The following example shows a server and a client using the protobuf.socketrpc Python API.
Server side
// Start server
server = protobuf.socketrpc.server.SocketRpcServer(port)
server.registerService(MyServiceImpl())
server.run()
Client Side
// Define callback
class Callback:
def run(self,response):
print "Received Response: %s" % response
// Create channel
channel = protobuf.socketrpc.channel.SocketRpcChannel(hostname,port)
controller = channel.newController()
// Call service
service = MyService_Stub(channel)
service.myMethod(controller,request,Callback())
// Check success
if controller.failed():
print "Rpc failed %s : %s" % (controller.error,controller.reason)Further examples
There are two more examples included in the source tarball. You might also want to have a look at the unit tests.
What are these magical MyServiceImpl and MyService_Stub of which you speak?
MyServiceImpl extends the MyService class generated by the protocol buffer compiler (protoc) from a .proto file (not shown - view other examples in tarball). MyService_Stub is also generated by protoc.
Documentation seems to be incomplete.Need a good documentation.
MyService_Stub? is the stub that is generated by the protocol buffer compiler. MyServiceImpl? is the server side implementation of the service RPC service that you have to implement.
You can find examples at: http://code.google.com/p/protobuf-socket-rpc/source/browse/#svn%2Ftrunk%2Fpython%2Fsrc%2Fprotobuf%2Fsocketrpc%2Fexamples%2Fhelloworld