Thomas Step

This is where I share my thoughts and experiences that I encounter developing software.



8 March 2019


by Thomas

I recently completed a school project about Remote Procedure Calls (RPC), in particular Google’s version (gRPC). The project was for my distributed objects programming course. The idea behind the project was to realize that communication between machines in two different locations can be simple and the API can look exactly like a local procedure call. gRPC handles all of the complicated socket programming behind the scenes. You just have to fill in the blanks of what the functions do whenever they are called, which would have to be done anyway. My repo for this project can be found here. You will see some commits in there from my partner Shawn. He took care of the client side and I did all of the Interface Description Language (IDL) setup and server side code. The only files that I worked with in depth were and tsns.proto. Starting off, any gRPC library that you are writing will need a proto file. Here you use protocol buffers like you would JSON (if you are familiar with that) to define what will be passed back and forth between the server and clients, and you will define the functions that can be used by the client (in my code the section containing Login(Auth), Follow(ToggleFollow), etc.). This does not have to be done correctly the first time because you can always go back in and add or edit your protocol buffers and functions. This is all pretty well documented on gRPC’s site. I used the command in my file to use gRPC’s file generation. The code can be generated in numerous languages, but I chose to use Python. After the Python files were generated, I created my own file, created a class inherited from the Servicer class that gRPC generated in the tsns_pb2_grpc file, filled in the blanks, and the server was good to go. Starting on line 222 in you can see how I started the server and passed in my custom Servicer class to be used for computation whenever a client called the functions (procedures) that I defined in the proto file. I just define the API functions and gRPC handles all of the networking for me. My hope is that the code that is on GitHub will suffice as documentation and reference but if you have any questions, I would be happy to help. If I ever come across a problem that needs an API, gRPC will be another tool that I can use to quickly create one.

tags: dev - python