Computer Science 15-112, Fall 2011
Class Notes: Client-Server and Peer-to-Peer Programming
- Required Reading
- Google App
Engine Tutorial
- (Overly) Simple
Client-Server Example
- (Overly) Simple
Peer-to-Peer Example
Client-Server
and Peer-to-Peer Programming
- Required Reading
-
Google App Engine, Python Overview
-
Google App Engine, Getting Started with Python 2.7
-
Google App Engine, Common Tasks in Python
- Google App
Engine Tutorial
Follow these Getting Started steps for
Google App
Engine:
-
Sign up for an
App Engine account.
-
Download the App Engine SDK.
(Note: You may first need to install Python 2.5, even though we
will be using Python 2.7.)
- 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.)
- (Overly) Simple
Client-Server Example
To get started:
- 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).
- On your computer, create your app folder, say with
the same name as your application (test1-cmu-koz in this example).
- 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.
- 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.
- Test Locally
- Run Google App Engine Launcher
- Select File/Add Existing Application, then select
the app folder you created above.
- Your app should now appear in the list of apps.
Select the app.
- Then, select the Run button. Now your app is
running in a web server on your local machine at
http://localhost:8080/
- Select the "Browse" button, which opens a browser
at http://localhost:8080/
- If this worked, you should see this in a browser:
hello from simpleApp0
- Test Remotely (online)
- Run (or stay in) Google App Engine Launcher
- Select your app in the list of apps.
- Select the "Deploy" button. Wait for a while
until the window says it succeeded and you can close it.
- Open a browser and go to your appspot address,
similar to this:
http://test1-koz-cmu.appspot.com/
- 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:
- Deal with exceptions (see
simpleApp1.py)
- Read http get/post parameters (see
simpleApp2.py)
- Include a simple (and not very secure) cmd
dispatcher (see simpleApp3.py)
- 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.
- 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).
- Demo a simple server with login/logout for
sharing IP addresses among Python clients
- 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!
- 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!
- (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