App Dev Notes
App Dev Notes
Mobile Apps
Targeted at mobile platforms: phones / tablets
Constraints
Limited screen space
Memory / processing
Power
Frameworks
OS specific
Cross-platform
Network!
Usually network oriented
Web Apps
The Platform
Works across OS, device: create a common base
Heavily network dependent
Workarounds for offline processing
L1.2: Components of an App
Exmaple: email client
Storage
Where are the emails stored ?
How are they stored on the server ? File formats etc...
Compute
Indexing of emails
Searching
Presentation
Display list of mails
Rendering/display of individual mails
Platform features
Desktop
Keyboard, mouse, video
Desktop paradigm - folders, files, documents
Mobile
Touchscreen
Voice, tilt, camera interfaces
Small self-contained apps
Web-based
Datacenter storage - persistent
Cloud: access anywhere, multi-device
Embedded
Single function, limited scope
Example: Watch, Camera (they are acessible separately, but are embedded in mobiles)
Machine clients
Eg: Software / antivirus updaters
Need not have user interaction
Variants
Multiple servers, single queue, multiply queues, load balancing frotends
Example:
Email
Databases
WhatsApp / messaging
Web browsing
Peer-to-Peer Architecture (distributed model)
Error tolerance
Masters / introducers
Election / re-selection of masters on failure
Shared information
Examples:
Bittorrent
Blockchain-based systems
IPFS, Tahoe (distributed file systems)
Model
The model represents the data of the application. It contains the business logic and rules for how the data is stored and
manipulated.
View
The view is responsible for displaying the data to the user. It renders the data into a graphical user interface (GUI) that
the user can interact with.
Controller
The controller mediates between the model and the view. It receives user input from the view and updates the model
accordingly. It executes the business logic of the application.
Model : The model would contain a list of todo items. Each todo item would have a title, a description, and a status
(e.g., "pending", "in progress", or "complete").
View : The view would be a web page that displays the list of todo items. The user would be able to add, edit, and
delete todo items from the view.
Controller : The controller would handle user input from the view. When the user adds a todo item, the controller
would add the item to the model. When the user edits a todo item, the controller would update the item in the
model. When the user deletes a todo item, the controller would delete the item from the model.
Others
IBM SNA, Digital DECNet, Xerox Ethernet, ...
Protocol:
A set of rules that defines how the data packets are formed and placed on wires.
How to format packets, place them on wire, headers/checksums.
Each network had its own protocol
"Inter" network
How to communicate between differnet network protocols ?
Or replace them with a single "Inter" net protocol.
HyperText ~1989+
Used to format the text, how it displayed.
Text documents to be "served"
Formatting hints inside document to "link" to other documents - HyperText
Web 3.0
Decentralized websites with blockchain technology.
Served as a platform for trustless transactions and ownership.
HTTP
HyperText
Regular text document
Cotnains "code" inside that indicate special functions - how to "link" to other documents
state information about the client, such as what pages the client has visited or what information the client has
entered into forms.
while true ; do
echo -e "HTTP/1.0 200 OK \n \n $( date ) "
| nc -l localhost 1800 ;
done
This Bash script creates a simple HTTP server that listens on port 1800 of the localhost indefinitely. It responds with
an HTTP 200 OK response containing the current date and time whenever a connection is made.
$ bash
simple_server.sh
terminal 1 (server)
Now, in another terminal, send an HTTP request at 1800 port (localhost) using curl
$ curl
http://localhost:1800
terminal 1 (server)
terminal 2 (request)
Whenever we try to send an HTTP request, the request will be shown in the server (terminal 1 )
terminal 1 (server)
terminal 2 (another request)
terminal 2 (request)
terminal 1 (server)
A Typical request
GET shows it's a GET request, we are requesting information from the server.
HOST the request URL, it's localhost at port 1800
is
User-Agent tells us the agent name who is requesting it, by default it is curl/version we modified it above using
-A command.
Accept indicates MIME types that the client is willing to accept
Loopback Address
A loopback address is a special IP address that is used to test the network stack of a computer.
It is not a real address, and packets sent to a loopback address are not sent over the network.
Instead, they are looped back to the computer that sent them.
IPv4 127.0.0.1
IPv6 ::1
Loopback addresses are useful for testing network connectivity and for debugging network problems.
For example, you can use a loopback address to test whether your computer is able to resolve DNS
names and to test whether your computer is able to connect to other computers on the network.
L1.8: Protocol
Both sides agree on how to talk.
Server expects requests
Nature of request
Nature of client
Client expects responses
Ask server for something
Convey what you can accept
Read result and process
HEAD Info Gets the headers for a resource without getting the body.
The request has not been fully processed yet, but the client should continue
100 Continue
with the request.
Switching
101 The server is switching protocols and the client should switch as well.
Protocols
102 Processing The request is still being processed and the client should wait for a response.
Successful
Status
Color Description
Code
Non-Authoritative The request has been successfully completed, but the information
203
Information returned may be from a different source.
The request has been successfully completed, and the client should reset
205 Reset Content
the document view.
The request has been successfully completed, and the client should only
206 Partial Content
return part of the document.
Redirection
Status
Color Description
Code
The client should make a new request to the URI specified in the Location header
303 See Other
field.
304 Not Modified The requested resource has not been modified since the last request.
Temporary The client should make a new request to the URI specified in the Location header
307
Redirect field, but only temporarily.
Permanent The client should make a new request to the URI specified in the Location header
308
Redirect field, and this redirect should be treated as permanent.
Client Error
Status
Color Description
Code
411 Length Required The request did not specify the length of the message-body.
413 Payload Too Large The request entity is larger than the server is willing or able to process.
414 URI Too Long The URI requested is longer than the server is willing to interpret.
Unsupported Media The request entity has a media type that the server is not willing or able
415
Type to handle.
The server cannot meet the expectation given in the Expect request-
417 Expectation Failed
header field.
Server Error
Status
Color Description
Code
The server does not support the functionality required to fulfill the
501 Not Implemented
request.
502 Bad Gateway The server received an invalid response from an upstream server.
504 Gateway Timeout The server did not receive a timely response from an upstream server.
$ python3 -m http.server
$ curl
http://localhost:8000
While sending a request, server is also showing what request is being made.
Now, let's create an index.html file in the server and make request again.
index.html file content:
As we can see, now only the content of index.html file we get as response.
Because, index.html file is typically set as the default or entry point file for web servers to serve when a user
requests a specific directory or domain.
L1.9: Performance
Latency
Latency is the time it takes for a request to travel from the client to the server and back.
Speed of light is 3 × 1 0 8 m/s. in vacuum, and 2 × 1 0 8 m/s in copper cable.
Approximates to 5 m s per 1000 km.
Example:
Data center is 200km away
One way request takes 10 m s
Round trip will take 20 m s
which is max 50 requests per second, not good enough.
Response size
Response size is the amount of data that is sent from the server to the client.
Example:
Response = 1KB of text (HTML, CSS, JS)
Network connection = 100 Mbps = 10 MByte/s
which approximates to 10 , 000 requests per second ( 100 M b p s ∗ 1 ).
Server will crash if more than 10 , 000 requests per second are made.
Now we can either open it in any browser directly by clicking on the file in system's file explorer.
Or, We can host a Local server - LAN server to serve this file.
To host a LAN server, we can use Python's built-in HTTP server module.
In terminal, we will write the below command to host a server.
python -m http.server
127.0.0.1:8000
For the above sample, the HTML will be rendered as:
Extra
There are 65,535 port numbers available in total for communication between devices in TCP.
The port numbers are divided into 3 categories:
Well-known ports (0–1023) : These ports are reserved for well-known services, such as HTTP (port 80) and SMTP
(port 25).
Registered ports (1024–49151) : These ports are available for registration by organizations that want to use them
for their own services.
Dynamic/private ports (49152–65535) : These ports are available for anyone to use.
IPv4 vs IPv6
Feature IPv4 IPv6
192.168.1.1 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Example divided into 4 octets: divided into 8 groups of 4 hexadecimal digits:
192 , 168 , 1 and 1 2001 , 0 db8 , 85 a 3 , 0000 , 0000 , 8a2e, 0370 and 7334