CSE 124
2017 October 23: gRPC Example

To get started writing gRPC code, I’ve put together a small example based on an ATM machine client/server.

To get access to this code, check it out from the GitHub repo. Note that you’ll need your ssh access key to clone the respository (even though it is public). To do this, you’ll want to use ssh forwarding:

$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa   <--- or whereever your github key is located
$ ssh -A csXXXX@ieng6.ucsd.edu

The above steps can be skipped if you generated your GitHub ssh key on the ieng6 servers. Once you get on the servers, you should be able to check out the repo via:

$ git clone git@github.com:gmporter/cse124-lec-grpc.git

There are two “tags” registered with this repository:

  • fullversion: A version with enough code to check for a valid account in the login() method
  • startercode: A clean, starter code environment for getting started. This code only implements a ping() method

To switch between the versions, you can run the “checkout” command:

$ git checkout startercode
$ git checkout fullversion

To build the code, run these two commands:

$ mvn protobuf:compile protobuf:compile-custom
$ mvn package

At this point, two commands will be created for you, one to run the server, and one to run the client.

$ ls target/atm/bin
runClient  runClient.bat  runServer  runServer.bat
$

To run the server:

$ target/atm/bin/runServer
Oct 20, 2017 4:45:17 PM atm.ATMServer main
SEVERE: Usage: atm.ATMServer <port>
$ target/atm/bin/runServer 5001
Oct 20, 2017 4:45:53 PM atm.ATMServer start
INFO: Server started, listening on 5001

To run the client:

$ target/atm/bin/runClient
Oct 20, 2017 4:46:37 PM atm.ATMClient main
SEVERE: Usage: atm.ATMClient host port
$ target/atm/bin/runClient localhost 5001
Oct 20, 2017 4:47:00 PM atm.ATMClient testConnectivity
INFO: Testing connectivity to localhost:5001
Oct 20, 2017 4:47:01 PM atm.ATMClient testConnectivity
INFO: Server is up!
Oct 20, 2017 4:47:01 PM atm.ATMClient login
INFO: Logging into the server with account 1234 and pin 5555
Oct 20, 2017 4:47:01 PM atm.ATMClient login
INFO: Got a login token of 1
Oct 20, 2017 4:47:01 PM atm.ATMClient login
INFO: Logging into the server with account 1234 and pin 212
Oct 20, 2017 4:47:01 PM atm.ATMClient login
WARNING: RPC failed: Status{code=INVALID_ARGUMENT, description=No such account number, cause=null}
Oct 20, 2017 4:47:01 PM atm.ATMClient login
WARNING: Reason: No such account number
$