You are on page 1of 26

Course Introduction

OSI reference model


services

interfaces protocols

TCP/IP reference model Example protocols

Where do the layers reside?


Which layers are implemented by OS?

The interfaces between OS and

applications

Socket API

What is the course about?


Application designs: Client designs Server designs Application implementations: Socket APIs Interaction of applications and TCP/IP stack Application protocols
RTP, RTSP, SIP

Standard Application Protocols


Standard applications:

well documented, standardized and adopted as official TCP/IP suite


email

Let us look more closely

at telnet (multiple choice) telnet application can be used to


A. Remotely access terminals B. Remotely access services C. Send an email D. Fetch a web page

Examples

telnet ftp More?

Fetching a web page using telnet


1. Telnet to your favorite Web server:
telnet cis.poly.edu 80

Opens TCP connection to port 80 (default http server port) at cis.poly.edu. Anything typed in sent to port 80 at cis.poly.edu

2. Type in a GET http request:


GET /~ross/ HTTP/1.0

By typing this in (hit carriage return twice), you send this minimal (but complete) GET request to http server

3. Look at response message sent by http server!


5

Scenario: Alice sends message to Bob


1) Alice uses MUA to compose message and to bob@someschool.edu 2) Alices MUA sends message to her mail server; message placed in message queue 3) Client side of SMTP opens TCP connection with Bobs mail server
4) MTA (Message Transfer Agent) in mail server sends Alices message over the TCP connection 5) Bobs mail server places the message in Bobs mailbox 6) Bob invokes his user agent to read message

1 mail user agent 2

mail server 3

mail server 4 5 6

mail user agent

Sample smtp interaction


S: C: S: C: S: C: S: C: S: C: C: C: S: C: S: 220 hamburger.edu HELO crepes.fr 250 Hello crepes.fr, pleased to meet you MAIL FROM: <alice@crepes.fr> 250 alice@crepes.fr... Sender ok RCPT TO: <bob@hamburger.edu> 250 bob@hamburger.edu ... Recipient ok DATA 354 Enter mail, end with "." on a line by itself Do you like ketchup? How about pickles? More messages? . 250 Message accepted for delivery QUIT 221 hamburger.edu closing connection
7

Sending an email using telnet


telnet servername 25

HELO your own domain name


MAIL FROM: <your own email address> RCPT TO: <recipient address> DATA QUIT

What can we learn here?


telnet goes beyond standard terminal access and

provides basic interactive communication facility

telnet protocol provides maximal flexibility

because it only defines interactive communication but not the details of the service accessed

Users at many sites may want to access the same

service at the same time. It is important yet challenging to provide concurrent services

Client-server model
Typical network app has two pieces: client and server Client:
initiates contact with server
application transport network data link physical

request

(speaks first) typically requests service from server, for Web, client is implemented in browser; for e-mail, in mail reader

reply
application transport network data link physical

Server:
provides requested service to client

e.g., Web server sends requested

Web page, mail server delivers email

10

More on Client Server Model


Clients initiate requests Servers wait for incoming requests and provide services

Servers always up and running Operating systems normally start servers automatically when they start

More differences Servers access system resources => special privileges Servers sometimes handle security issues

11

Connectionless vs. ConnectionOriented Protocols


Connectionless protocols UDP Fast Unreliable

Connection-oriented protocols TCP Slower Reliable

Examples

12

Stateless vs. Stateful Protocols


Stateful protocols Keeping states in the servers Reducing the size and number of messages Applications sometimes need session information Stateless protocols Simple Protocol reliability example Stateless file server Stateful file server

13

How to keep track of clients?


Two ways
End points (IP address, port number) What is wrong? Handles

A short identifier allocated by the server, stored in servers database and sent to the client

14

Keeping track of clients: handles

user accounts Web portals

shopping carts

Advertising Secretly collecting users browsing habits


What to do?

15

More on Stateful Protocols


Keeping correct states is challenging What happens when clients crash and reboot? What happens when messages arrive out of order, get duplicated or get lost? Keeping states sometimes poses security

risks

Tracking browsing patterns Loss of confidential information (e.g. credit card number, ssn)

16

Concurrent Processing
Concurrent Processing:

Why is it needed? Achieving concurrent processing


Concurrency in clients

Time sharing multiprocessing

Concurrency in servers

no special efforts by client programmers

Special efforts needed by server programmers


Multiple processes Multiple threads

17

Processes and Threads


Processes
Fundamental

unit of computation An address space and at least one thread of execution (instruction pointer)
Thread Light-weight process
Program vs process

Static concept

18

Sharing of Variables
Local Variable Rule - When

multiple processes or threads execute a piece of code concurrently, each creates its own independent copy of the variables associated with the code (local variables) process creates a copy of global variables, but multiple threads within a single process share the processs global variables

int x; for (i=1; i<=10; i++) printf (%d\n, i+x);

Global Variable Rule - Each

19

Procedure Calls

Procedure Call Rule - When multiple threads execute a piece of code concurrently, each has its own stack of procedure activation records Example - Putting the rules together!

20

Example of Concurrent Process Creation


Example 1 Sequential processing Example 2 Concurrent version
Computationally light Computationally intensive

Both processes do the same job!

21

Sequential C Example
/* seq.c - A conventional C program that sums integers from 1 to 5 */ #include <stdlib.h> #include <stdio.h> int sum; /* global variable */ main() { int i;

/* local variable */

sum = 0; for (i=1; i<=5; i++) { /* iterate from 1 to 5 */ printf(The value of i is %d\n, i); fflush (stdout); /* flush buffer */ sum += i; } printf (The sum is %d\n, sum); exit (0);

}
22

Concurrent C Example
/* concurr.c - A concurrent C program that sums integers from 1 to 5 */ #include <stdlib.h> #include <stdio.h> int sum; /* global variable */ main() { int i;

/* local variable */

sum = 0; fork(); for (i=1; i<=5; i++) { /* iterate from 1 to 5 */ printf(The value of i is %d\n, i); fflush (stdout); /* flush buffer */ sum += i; } printf (The sum is %d\n, sum); exit (0);
}
23

Concurrent Processes (II)


Processes perform different tasks
Distinguished by the return value of fork() fork and execve allow newly created processes to execute an

independent, separately-compiled program

/* sum.c - A concurrent C program that performs different tasks for two processes */ #include <stdlib.h> #include <stdio.h> main() { int pid; /* local variable */ pid=fork(); if (pid != 0) { /* original process */ printf(The original process prints this.\n); } else { /* newly created process */ printf (The new process prints this.\n); } exit(0); } 24

Concurrency in I/O
Let us take a browser as an example It needs to respond to input from users

It needs to respond to input from the network

Mouse clicks Keyboard input

It needs to send request to the network

Downloaded web pages, images, Send a HTTP request

How to handle this scenario? Asynchronous I/O (aka non-blocking I/O) Concurrency in I/O

select system call

25

Lab Exercises
Use telnet to send an email to yourself

Concurrent processing Modify concurr.c so that the messages printed from parent and child processes are different Observe how the messages from parent and child are interleaved in the output Write and compile the summation procedure as a separate program and use execv() to call it in the child process

26

You might also like