My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
PythonUsage  
A simple usage example for Python
Python, Example
Updated Nov 4, 2010 by sdeo.code@gmail.com

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.

Comment by Norl...@gmail.com, Feb 24, 2011

What are these magical MyServiceImpl and MyService_Stub of which you speak?

Comment by Norl...@gmail.com, Feb 24, 2011

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.

Comment by i.ankit....@gmail.com, May 1, 2011

Documentation seems to be incomplete.Need a good documentation.

Comment by project member sdeo.code@gmail.com, May 11, 2011

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


Sign in to add a comment
Powered by Google Project Hosting