def do_POST(self):
     self.send_response(200)
     self.send_header('Content-type','application/x-protobuf')
     self.end_headers()
     contentlength = string.atoi(self.headers.getheader('content-length')) 
     data = self.rfile.read(contentlength) 
     input = square_input()
     input.ParseFromString(data)
     self.rfile.close()
     output = self.square_messages(input)
     self.wfile.write(output.SerializeToString())
     self.wfile.close()
#!/usr/bin/python

import httplib, urllib

from messages.square_messages_pb2 import square_input, square_output


input = square_input()
input.value = 18

params = input.SerializeToString()
headers = {"Content-type": "application/x-protobuf","Accept": "application/x-protobuf", "Content-length": len(str(params))}
conn = httplib.HTTPConnection("localhost:1234")
conn.request("POST", "/", params, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
conn.close()

output = square_output()
output.ParseFromString(data)

print output.value

#!/usr/bin/python

from messages.square_messages_pb2 import square_input, square_output

def square_messages(input):
    retval = square_output()
    retval.value = (input.value)*(input.value)
    return retval

sq_in = square_input()
sq_in.value = int(raw_input("Number to square: "))


print "Input"
print sq_in.value


sq_out = square_messages(sq_in)

print "Result:"
print sq_out.value