Computer Science 15-112, Fall 2011
Class Notes:  Client-Server and Peer-to-Peer Programming


  1. Required Reading
  2. Google App Engine Tutorial
  3. (Overly) Simple Client-Server Example
  4. (Overly) Simple Peer-to-Peer Example

Client-Server and Peer-to-Peer Programming

  1. Required Reading
    1. Google App Engine, Python Overview
    2. Google App Engine, Getting Started with Python 2.7
    3. Google App Engine, Common Tasks in Python
       
  2. Google App Engine Tutorial
    Follow these Getting Started steps for Google App Engine:
    1. Sign up for an App Engine account.
    2. Download the App Engine SDK.
      (Note:  You may first need to install Python 2.5, even though we will be using Python 2.7.)
    3. Read the Getting Started Guide for Python 2.7
      (Note:  Do all these steps, but don't worry too much about the complexities of the Datastore, and you may even skip "Using Templates" and "Using Static Files" for now.)
       
  3. (Overly) Simple Client-Server Example
    To get started:
     
    1. Go to https://appengine.google.com/  and select "Create Application".  In our example, the application is named test1-cmu-koz, but you should give yours a unique name (say, with your own andrewId).
       
    2. On your computer, create your app folder, say with the same name as your application (test1-cmu-koz in this example).
       
    3. In your app folder, copy this file:  app.yaml
      Then edit it so that the application name on the first line refers to the name you created in step 1 above.
       
    4. In your app folder, copy this file:  simpleApp0.py
      Then, rename it to simpleApp.py (as this is the file that app.yaml expects to contain your app).  At each step N below, we will provide you with simpleAppN.py, but keep the file named simpleApp.py (no N) throughout this example.  This initial version simply prints hello, allowing us to verify that the plumbing is basically working before we proceed.
       
    5. Test Locally
      1. Run Google App Engine Launcher
      2. Select File/Add Existing Application, then select the app folder you created above.
      3. Your app should now appear in the list of apps.  Select the app.
      4. Then, select the Run button.  Now your app is running in a web server on your local machine at http://localhost:8080/
      5. Select the "Browse" button, which opens a browser at http://localhost:8080/
      6. If this worked, you should see this in a browser:
        hello from simpleApp0
         
    6. Test Remotely (online)
      1. Run (or stay in) Google App Engine Launcher
      2. Select your app in the list of apps.
      3. Select the "Deploy" button.  Wait for a while until the window says it succeeded and you can close it.
      4. Open a browser and go to your appspot address, similar to this:  http://test1-koz-cmu.appspot.com/
      5. As with above, if this worked, you should see this in a browser:
        hello from simpleApp0
        Note that the first time you deploy the app, it may take a while (maybe 5-10 minutes) before you can use it.

    And now we're ready to write out simple client-server example.  Here are the step-by-step improvements:
     

    1. Deal with exceptions (see simpleApp1.py)
    2. Read http get/post parameters (see simpleApp2.py)
    3. Include a simple (and not very secure) cmd dispatcher (see simpleApp3.py)
    4. Include simple (maybe too simple) read/write to db (see simpleApp4.py)
      Note:  To remain simple, we just store (name,value) string pairs.  This basically end-runs the whole loader/exporter framework in Google App Engine, so it's really just a simplistic way to get going. If you're serious, learn how to use that framework, such as explained here.
    5. Include simple (in fact, too simple!) authentication (see simpleApp5.py)
      Note:  To remain simple, we just keep a list of passwords in a single db entry. This does not scale!!!!  This basically end-runs the whole authentication framework in Google App Engine, so it's really just a simplistic way to get going (while making it easy to use this from non-browser-based Python apps without having to enter your Google password, which ultimately is why we are not using the default Google account authentication).
    6. Demo a simple server with login/logout for sharing IP addresses among Python clients
      1. Web server (see simpleApp6.py)
        Note:  This is overly simplistic with little/no security.  Any client with the user name of another client can obtain the IP address for that other client.  This is only for demonstrational purposes!
      2. Python client (see simpleClient6a.py)
        Note:  this is a client to go along with simpleApp6.py.  Just lets you login and logout, and also get the IP address of someone else who is logged in (only useful if you are on the same LAN).  As with the accompanying server, this is overly simplistic with little/no security.  This is only for demonstrational purposes!
         
  4. (Overly) Simple Peer-to-Peer Example
    We briefly reviewed this standard Python sockets example, which includes client.py and server.py.

carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem