03-Role of the Server in Mobile Applications

Homework required in preparation for this lecture

  1. Team homework - Server's schema
    1. Discuss and decide tables of data your game or product will require to be stored on the server. 
    2. You should identify at least one and no more than 5 tables.
    3. And example might be:  e.g. users (name, lastLogInDateTime), mood_record (UserId, happy_sad, gps) etc.
    4. Deliverable: A group blog post with your product's tables, their columns and data types
  2. XML Returned by a web service
    1. Imagine that you ask your server for information on one of the tables, for example, user == "pito salas"
    2. Write a little xml showing what the result of that request might look like
    3. Deliverable: An individual blog post with that write up. Make sure that all your proposed tables are covered by someone on the team.
  3. Read intro to Rails Guide
    1. There is a lot of information there beyond the step by step instructions
    2. You are reading this to get a general exposure to the concepts. 
    3. You don't need to actually follow the step by step procedure

Learning goals

  • understand the role of a server in a mobile app
    • understand the end-to-end process of getting from a client to server and back
    • concept of a database backed web site or server - html and xml
  • general architecture of such a site
    • tease a url apart and how surfing might work
  • understand some of the tools used to build a site
    • ruby on rails, 
    • apache, 
    • Mysql and other SQL databases
    • Operating System (e.g. Linux)
  • From web sites to web services
    • HTTP, REST and XML

Basics - Urls And Web Servers

  • let's tease a url apart: http://www.salas.com/2003/05/31/no-i-dont-really-have/
  • a server is a computer that is connected to the internet
  • meaning it has an IP address and can receive requests
  • a server 'talks' one or more protocols, 
    • e.g. TCP/IP, HTTP, DNS, UDP, etc., which means that when such a request comes to it, it knows what to do.

What is needed to 'create' a simple web server?

  • design the html pages (which are just text files)
  • connect a computer to 'the internet'
  • make that computer act like a web server
  • give it the html pages
  • So far, all web pages are static. In real life, this is almost never the case
  • Web pages are built-on the fly-by code
  • So? http://www.salas.com/2003/05/31/no-i-dont-really-have/

Fake Code

  • Conceptually:

// Method prototype
String get(String server, String protocol, String parameters...)

// Get html string
html_result = get("www.salas.com", "http", "2003/05/31/no-i-dont-really-have/");

Web Services

  • Can we think of the web server as more than something that we can surf to with a web browser?
  • Discuss web page scraping and what is wrong with that
  • What if the data were available as well, what would be possible?
  • A Web server receives a URL and sends back HTML etc.
  • A Web service receives a URL and sends back Data (XML etc.)

Looking at some examples

  • Weatherbug
    • Play with it using my apieky
    • Maybe want to let user pick a city for giraffe adventure and show actual weather there?
    • Maybe HappySad wants to try and correlate emotional status with the weather?
  • BestSchools
    • Maybe you have a real estate app to help people decide where to live
  • arXiv (http://arxiv.org/)
    • Play with the API here: http://arxiv.org/help/api/index (click)
    • Maybe you want to analyze research papers or study reference chains
  • Amazon web service
  • VoguableApp service

Http

  • One of the foundational protocols of the web (other ones are?)
  • Request -> Response. Stateless.
  • HTTP Protocol
  • At the heart: a way to deliver 'URL' in to a 'Web Server' and tell it what to do with it and then process the result (TCP/IP not required!)
  • URL -- URI?
  • HTTP methods: GET, PUT, POST, DELETE... and others
  • HTTP Request: Do <method> to this <url> resource.
  • HTTP Response: <status> happened. Here's the result: <result>

Shell Demo of HTTP

$ telnet www.salas.com 80
Trying 64.34.168.137...
Connected to salas.com.
Escape character is '^]'.
GET / HTTP/1.0
Host: Salas.com

HTTP/1.1 301 Moved Permanently
...
~ $ telnet www.salas.com 80
Trying 64.34.168.137...
Connected to salas.com.
Escape character is '^]'.
GET / HTTP/1.1
Host: www.salas.com

HTTP/1.1 200 OK
Server: nginx/0.5.31
Date: Fri, 28 May 2010 14:57:08 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/4.3.9
X-Pingback: http://www.salas.com/xmlrpc.php
Set-Cookie: wwsgd_visits=1; expires=Sat, 28-May-2011 14:57:08 GMT; path=/

edc
<!DOCTYPE html PUBLIC "-//W3C

More information

Protocols

  • A protocol is a set of rules. Abstraction. Leaky Abstraction.
  • Protocols determine the way information is interpreted 'on the wire'
  • You can think of them as 'envelopes'
  • Imagine I mail a big box of books to 'brandeis unversity, South Street, Waltham MA'
  • Inside the box there are smaller boxes: 'computer science dept', 'math dept', etc.
  • Each book is in an envelope: J. Smith, F. Johnson, etc.
  • So with protocols are the first set of bits the 'higher' or 'lower' level protocol?

Tcp/Ip

  • transport control protocol, on TOP of IP
  • handles delivery of those bits to and from a particular "application" to another "application"
  • adds a 'port' number to IP
  • the 'application' aka the 'server' and the other application aka the 'client'
  • Sockets

Afternoon Schedule

  • Teams work with clients
  • Review homework for tomorrow's lecture.