Internet Topics Client-server programming model Networks in general

Slides:



Advertisements
Similar presentations
Carnegie Mellon 1 Internetworking : Introduction to Computer Systems 19 th Lecture, Oct. 28, 2010 Instructors: Randy Bryant and Dave O’Hallaron.
Advertisements

Network Programming Topics Peeking at Internet traffic Programmer’s view of the Internet (review) Sockets interface Writing clients and servers Understanding.
Chris Riesbeck, Fall 2007 Network Programming Topics –Sockets interface –Writing clients and servers.
Carnegie Mellon 1 Network Programming : Introduction to Computer Systems 20 th Lecture, Nov. 2, 2010 Instructors: Randy Bryant and Dave O’Hallaron.
Networks and Network Programming May 24, 2006 Topics Client-server programming model Networks A programmer’s view of the Internet Sockets interface Writing.
Networks and Network Programming June 2, 2008 Topics Client-server programming model Networks A programmer’s view of the Internet.
Internetworking Nov 19, 2002 Topics Client-server programming model Networks Internetworks Global IP Internet IP addresses Domain names Connections class25.ppt.
– 1 – CS213, S’08 Network Programming June 4, 2008 Topics Sockets interface Writing clients and servers.
Network Programming November 19, 2007 Topics Peeking at Internet traffic Programmer’s view of the Internet (review) Sockets interface Writing clients and.
Network Programming Nov. 6, 2008 Topics Peeking at Internet traffic Programmer’s view of the Internet (review) Sockets interface Writing clients and servers.
Network Programming Nov 21, 2002 Topics Programmer’s view of the Internet (review) Sockets interface Writing clients and servers class26.ppt “The.
Chris Riesbeck, Fall 2007 Internetworking Topics –Client-server programming model –Networks –Internetworks –Global IP Internet IP addresses Domain names.
Networking S04, Recitation, Section A
1. Networks and the Internet 2. Network programming.
Recitation 12: 11/25/02 Outline Socket Interface –Echo Client/Server Http Protocol Evaluation Annie Luo Office Hours: Thursday.
Internetworking Topics Client-server programming model Networks Internetworks Global IP Internet IP addresses Domain names Connections CS 105 “Tour of.
CS- 492 : Distributed system & Parallel Processing Lecture 2: 9/4/1435 Sun  networking.  internetworking essentials.  overview of network programming.
University of Amsterdam Computer Systems – Iterative server Arnoud Visser 1 Computer Systems Iterative server.
Computer Systems II CSC 2405 Network Programming.
Carnegie Mellon Internetworking /18-213: Introduction to Computer Systems 20 th Lecture, March 31st, 2015 Instructors: Franz Franchetti, Seth Goldstein,
Network Programming Topics Programmer’s view of the Internet Sockets interface Writing clients and servers CS 105 “Tour of the Black Holes of Computing!”
The Application Layer Application Services (Telnet, FTP, , WWW) Reliable Stream Transport (TCP) Connectionless Packet Delivery Service (IP) Unreliable.
Instructors: Greg Ganger, Greg Kesden, and Dave O’Hallaron
Recitation 12 (Nov. 29) Outline Socket programming Lab 7: part 1 Reminder Lab 7: Due next Thursday Minglong Shao Office hours: Thursdays.
Carnegie Mellon 1 Internetworking / : Introduction to Computer Systems 20 th Lecture, July 10, 2014 Instructors: Greg Kesden.
Carnegie Mellon Introduction to Computer Systems /18-243, fall th Lecture, Nov. 3 rd Instructors: Roger Dannenberg and Greg Ganger.
Carnegie Mellon 1 Network Programming / : Introduction to Computer Systems 21 st Lecture, Nov. 7, 2013 Instructors: Randy Bryant, Dave O’Hallaron,
Network programming Nov 16, 2000 Topics Client-server model Sockets interface Echo client and server class24.ppt “The course that gives CMU its.
Carnegie Mellon Introduction to Computer Systems /18-243, spring th Lecture, Nov. 5 th Instructors: Roger Dannenberg and Greg Ganger.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Network Programming: Part I : Introduction to.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
Internetworking Topics Client-server programming model Networks Internetworks Global IP Internet IP addresses Domain names Connections CS 105 “Tour of.
Carnegie Mellon 1 Network Programming / : Introduction to Computer Systems 21 st Lecture, Nov. 8, 2012 Instructors: Dave O’Hallaron, Greg.
Internetworking Topics Client-server programming model Networks Internetworks Global IP Internet IP addresses Domain names Connections CS 105 “Tour of.
Internetworking Topics Client-server programming model Networks Internetworks Global IP Internet IP addresses Domain names Connections net1.ppt CS 105.
Carnegie Mellon Introduction to Computer Systems /18-243, spring rd Lecture, Apr. 14 th Instructors: Gregory Kesden and Markus Püschel.
1 Networking Programming (I). 2 Outline Client-Server Programming Model Networks The Global IP Internet Suggested Reading: –11.1, 11.2, 11.3.
1 Networking Programming. 2 Outline Connection & Socket Sockets Interface –Functions –Echo Client and Server Suggested Reading: –11.4.
1 Network Communications A Brief Introduction. 2 Network Communications.
Carnegie Mellon /18-243: Introduction to Computer Systems Instructors: Bill Nace and Gregory Kesden (c) All Rights Reserved. All work.
Carnegie Mellon 1 Network Programming / : Introduction to Computer Systems 21 st Lecture, April 2, 2015 Instructors: Franz Franchetti, Seth.
Computer networks Name: K.SUDHA Designation: Lecturer Department: Electrical and Electronics Engineering Subject code: CS2361 Year: III Unit: V Title:
Instructors: Gregory Kesden
Network Programming: Part I
CS 105 “Tour of the Black Holes of Computing”
Instructor: Randy Bryant
Extending echo server HTTP Broken pipe error Feedback and evaluation
Instructors: Anthony Rowe, Seth Goldstein and Greg Kesden
Network Programming /18-243: Introduction to Computer Systems
CS 105 “Tour of the Black Holes of Computing”
Network Programming April 11, 2008
Network programming Nov 27, 2001
“The course that gives CMU its Zip!”
Topic 5: Communication and the Internet
Recitation 11 – 4/29/01 Outline Sockets Interface
I. Basic Network Concepts
Basic Internet Components
Web Services Topics Proxies Sockets interface
Network Programming Chapter 12
Networking Programming
Network Programming: Part II CSCI 380: Operating Systems Lecture #13
System-Level I/O.
Networking Programming
Network Programming: Part I CSCI 380: Operating Systems
Network Programming: Part II CSCI 380: Operating Systems
Network Programming November 3, 2008
Internetworking April 17, 2003
Computer Networks DA2402.
Lecture 23: Networking and IP
Presentation transcript:

Internet Topics Client-server programming model Networks in general Internets Global IP Internet IP addresses Domain names Connections What is a socket?

A Client-Server Transaction Every network application is based on the client-server model: A server process and one or more client processes Server manages some resource Server provides a service by manipulating the resource for clients 1. Client sends request Client process Server process Resource 4. Client handles response 3. Server sends response 2. Server handles request Both client and server are processes running on hosts (can be the same or different computer).

Network is just another I/O device... can access with Unix I/O Network Connection CPU chip Network is just another I/O device... can access with Unix I/O register file ALU system bus memory bus main memory MI I/O bridge Expansion slots I/O bus USB controller graphics adapter disk controller network adapter mouse keyboard monitor disk network

Computer Networks A network is a hierarchical system of boxes and wires organized by geographical proximity LAN (local area network) spans a building or campus Ethernet is popular WAN (wide-area network) spans country or world Typically high-speed point-to-point phone lines An internetwork (internet) is an interconnected set of networks The Global IP Internet (uppercase “I”) is the most famous example of an internet (lowercase “i”) Let’s see how we would build an internet from the ground up.

Lowest Level: Ethernet Segment Ethernet segment consists of a collection of hosts connected by wires (twisted pairs) to a hub. Spans room or floor in a building. Operation The hub has a port for each host Each host has an Ethernet adapter with a unique 48-bit address Hosts send bits to any other host in chunks called frames Hub slavishly copies each bit from each port to every other port Every host sees every bit. host host host 100 Mb/s 100 Mb/s hub ports

LAN: Bridged Ethernet Segment Local Area Network Spans building or campus. Bridges cleverly learn which hosts are reachable from which ports and then selectively copy frames from port to port. A B host host host host host X hub bridge hub 100 Mb/s 100 Mb/s 1 Gb/s host host 100 Mb/s 100 Mb/s hub bridge hub Y host host host host host C

Conceptual View of LANs For simplicity, hubs, bridges, and wires are often shown as a collection of hosts attached to a single wire: ... host host host

Next Level: internets Multiple incompatible LANs can be physically connected by specialized computers called routers. The connected networks are called an internet. ... ... host host host host host host LAN 1 LAN 2 router router router WAN WAN LAN 1 and LAN 2 might be completely incompatible

The Notion of an internet Protocol How is it possible to send bits across incompatible LANs and WANs? Solution: protocol software running on each host. The router smoothes out the differences between the different networks. An internet protocol (i.e., set of rules) governs how hosts and routers should cooperate when they transfer data from network to network. TCP/IP is the protocol for the global IP Internet.

What Does an internet Protocol Do? 1. Provides a naming scheme An internet protocol defines a uniform format for host addresses Each host (and router) is assigned at least one of these internet addresses that uniquely identifies it 2. Provides a delivery mechanism An internet protocol defines a standard transfer unit (packet) Packet consists of header and payload Header: contains info such as packet size, source and destination addresses Payload: contains data bits sent from source host

Transferring Data Over an internet Host A Host B client server PH = Packet Header FH = Frame Header (1) (8) data data protocol software protocol software internet packet (2) (7) data PH FH1 data PH FH2 LAN1 frame LAN1 adapter LAN2 adapter Router (3) (6) data PH FH1 data PH FH2 LAN1 adapter LAN2 adapter LAN1 LAN2 LAN2 frame (4) data PH FH1 (5) data PH FH2 protocol software

Other Issues We are glossing over a number of important questions: What if different networks have different maximum frame sizes? (segmentation) How do routers know where to forward frames? How are routers informed when the network topology changes? What if packets get lost? These (and other) questions are addressed by the area of systems known as computer networking.

Global IP Internet Most famous example of an internet. Based on the TCP/IP protocol family IP (Internet protocol) : Provides basic naming scheme and unreliable delivery capability of packets (datagrams) from host-to-host. UDP (Unreliable Datagram Protocol) Extends IP to provide unreliable datagram delivery from process-to-process. TCP (Transmission Control Protocol) Extends IP to provide reliable byte streams from process-to-process over connections. Accessed via a mix of Unix file I/O and functions from the sockets interface.

Hardware and Software for an Internet Application Internet client host Internet server host Client Server User code Sockets interface (system calls) TCP/IP TCP/IP Kernel code Hardware interface (interrupts) Network adapter Hardware and firmware Network adapter Global IP Internet

A Programmer’s View of the Internet Hosts are mapped to a set of 32-bit IP addresses. 128.2.203.179 (4 bytes, each byte = 0..255) IPV4 (Internet Protocol Version 4) IPV6, the next generation standard, has 128-bit IP addresses The set of IP addresses is mapped to a set of identifiers called Internet domain names. 66.235.192.183 is mapped to epaperpress.com demo: ping epaperpress.com A process on one Internet host can communicate with a process on another Internet host over a connection.

IP Addresses 32-bit IP addresses are stored in an IP address struct IP addresses are always stored in memory in network byte order (big-endian byte order) True in general for any integer transferred in a packet header from one machine to another Specified as a struct due to historical reasons /* Internet address structure */ struct in_addr { unsigned int s_addr; /* network byte order (big-endian) */ }; Handy network byte-order conversion functions: htonl: convert long int from host to network byte order. htons: convert short int from host to network byte order. ntohl: convert long int from network to host byte order. ntohs: convert short int from network to host byte order.

Dotted Decimal Notation By convention, each byte in a 32-bit IP address is represented by its decimal value and separated by a period IP address 0x8002C2F2 = 128.2.194.242 Functions for converting between binary IP addresses and dotted decimal strings: inet_aton: converts a dotted decimal string to an IP address in network byte order. inet_ntoa: converts an IP address in network by order to its corresponding dotted decimal string. “n” denotes network representation. “a” denotes application representation. Demo: dd2hex 66.235.192.183 dd2hex 42ebc0b7

Internet Domain Names unnamed root mil edu gov com First-level domain names mit cmu berkeley amazon Second-level domain names cs ece www 208.216.181.15 Third-level domain names cmcl pdl kittyhawk 128.2.194.242 imperial 128.2.189.40

Domain Naming System (DNS) The Internet maintains a mapping between IP addresses and domain names in a huge worldwide distributed database called DNS. Conceptually, programmers can view the DNS database as a collection of millions of host entry structures: Functions for retrieving host entries from DNS: gethostbyname: query key is a DNS domain name. gethostbyaddr: query key is an IP address. /* DNS host entry structure */ struct hostent { char *h_name; /* official domain name of host */ char **h_aliases; /* null-terminated array of domain names */ int h_addrtype; /* host address type (AF_INET) */ int h_length; /* length of an address, in bytes */ char **h_addr_list; /* null-terminated array of in_addr structs */ };

Properties of DNS Host Entries Each host entry is an equivalence class of domain names and IP addresses. Each host has a locally defined domain name localhost which always maps to the loopback address 127.0.0.1 Different kinds of mappings are possible: Simple case: 1-1 mapping between domain name and IP addr: kittyhawk.cmcl.cs.cmu.edu maps to 128.2.194.242 Multiple domain names mapped to the same IP address: eecs.mit.edu and cs.mit.edu both map to 18.62.1.6 Multiple domain names mapped to multiple IP addresses: aol.com and www.aol.com map to multiple IP addrs. Demo: hostinfo

Domain Information Groper (dig) A command-line DNS lookup utility. How many hosts? See ISC. How are they related? See Google Browser psphoto, lexandyacc linux> dig +short kittyhawk.cmcl.cs.cmu.edu 128.2.194.242 linux> dig +short -x 128.2.194.242 KITTYHAWK.CMCL.CS.CMU.EDU. linux> dig +short aol.com 205.188.145.215 205.188.160.121 64.12.149.24 64.12.187.25 linux> dig +short -x 64.12.187.25 aol-v5.websys.aol.com.

Internet Connections Clients and servers communicate by sending streams of bytes over connections: Point-to-point, full-duplex, and reliable. A socket is an endpoint of a connection Socket address is an IPaddress:port pair A port is a 16-bit integer that identifies a process: Ephemeral port: Assigned automatically to client when client makes a connection request Well-known port: Associated with some service provided by a server (port 80 = web services) A connection is uniquely identified by the socket addresses of its endpoints (socket pair) (cliaddr:cliport, servaddr:servport)

Putting it all Together: The Anatomy of an Internet Connection Client socket address 128.2.194.242:51213 Server socket address 208.216.181.15:80 Client Server (port 80) Connection socket pair (128.2.194.242:51213, 208.216.181.15:80) Client host address 128.2.194.242 Server host address 208.216.181.15

Examples of Clients and Servers Examples of client programs Web browsers, ftp, telnet, ssh How does a client find the server? The IP address in the server socket address identifies the host (more precisely, an adapter on the host) The (well-known) port in the server socket address identifies the service, and thus implicitly identifies the server process that performs that service. Examples of well know ports Port 7: Echo server Port 23: Telnet server Port 25: Mail server Port 80: Web server

Using Ports to Identify Services Server host 128.2.194.242 Client host Service request for 128.2.194.242:80 (i.e., the Web server) Web server (port 80) Client Kernel Echo server (port 7) Web server (port 80) Service request for 128.2.194.242:7 (i.e., the echo server) Client Kernel Echo server (port 7)

Servers Servers are long-running processes (daemons). daemon = disk and execution monitor Created at boot time by the init process (process 1) Run continuously until the machine is turned off. Each server waits for requests to arrive on a well-known port associated with a particular service. echo server: port 7 telnet server: port 23 mail server: port 25 HTTP server: port 80

Server Examples Web server (port 80) FTP server (20, 21) Resource: files/run programs Service: retrieves files and runs CGI programs on behalf of the client FTP server (20, 21) Resource: files Service: stores and retrieve files Telnet server (23) Resource: terminal Service: proxies a terminal on the server machine Mail server (25) Resource: email “spool” file Service: stores mail messages in spool file See /etc/services for a comprehensive list of the services available

Sockets

Sockets Interface Created in the early 80’s as part of the original Berkeley distribution of Unix that contained an early version of the Internet protocols. Provides a user-level interface to the network. Underlying basis for all Internet applications. Based on client/server programming model.

Sockets What is a socket? To the kernel, a socket is an endpoint of communication To an application, a socket is a file descriptor that lets the application read/write from/to the network Remember: All Unix I/O devices, including networks, are modeled as files Clients and servers communicate with each by reading from and writing to socket descriptors The main distinction between regular file I/O and socket I/O is how the application “opens” the socket descriptors

Sockets Interface Client Server open_listenfd open_clientfd Connection bind open_listenfd open_clientfd listen Connection request connect accept rio_writen rio_readlineb Await connection request from next client rio_readlineb rio_writen EOF close rio_readlineb close

Echo Client/Server Iterative Server Client Action Demo (Ctrl-D = EOF) echoserveri 8000 Daemon that monitors port 8000 on server Client echoclient cs01.syi.pcc.edu 8000 connect to server at cs01.syi.pcc.edu on server’s port 8000 Action Client sends message to server Server echos back all text typed in by client Client displays messages received from server on stdout Demo (Ctrl-D = EOF) jupiter: echoserveri 8000 jupiter: echoclient 127.0.0.1 8000 (localhost) hostinfo jupiter.pcc.edu cs01: echoserveri 8000 jupiter: echoclient cs01.syi.pcc.edu 8000

Echo Server: Main Routine (p. 825) // echoserveri 8000 int main(int argc, char **argv) { int listenfd, connfd, port, clientlen; struct sockaddr_in clientaddr; char *haddrp; port = atoi(argv[1]); listenfd = open_listenfd(port); while (1) { clientlen = sizeof(clientaddr); connfd = Accept(listenfd, (SA *)&clientaddr, &clientlen); haddrp = inet_ntoa(clientaddr.sin_addr); printf("server connected to %s:%d\n", haddrp, port); echo(connfd); printf(“closing connection”); Close(connfd); }

Echo Client Main Routine (p. 824) // echoclient cs01.syi.pcc.edu 8000 int main(int argc, char **argv) { int clientfd, port; char *host, buf[MAXLINE]; rio_t rio; host = argv[1]; port = atoi(argv[2]); printf(“opening connection\n”); clientfd = Open_clientfd(host, port); Rio_readinitb(&rio, clientfd); while (Fgets(buf, MAXLINE, stdin) != NULL) { Rio_writen(clientfd, buf, strlen(buf)); Rio_readlineb(&rio, buf, MAXLINE); Fputs(buf, stdout); } printf(“closing connection\n”); Close(clientfd); exit(0);

Echo Server: echo function (p. 826) void echo(int connfd) { size_t n; char buf[MAXLINE]; rio_t rio; Rio_readinitb(&rio, connfd); while((n = Rio_readlineb(&rio, buf, MAXLINE)) != 0) { printf("server received %d bytes\n", n); Rio_writen(connfd, buf, n); }

Next Time Coverage includes More details on the socket interface Learn how “tiny”, a small web server, works