DOC PREVIEW
CMU CS 15441 - Lecture

This preview shows page 1-2-3-4-30-31-32-33-34-61-62-63-64 out of 64 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 64 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Network Programming Jan 13, 2005A Client-Server ExchangeNetwork ApplicationsInternet Connections (TCP/IP)ClientsUsing Ports to Identify ServicesServersOverview of the Sockets InterfaceSocketsSocket Programming ClichesSocket Programming HelpSocket Address StructuresReliable I/O (RIO) SummaryEcho Client Main RoutineEcho Client: open_clientfdEcho Client: open_clientfd (socket)Echo Client: open_clientfd (gethostbyname)Echo Client: open_clientfd (connect)Servers and sockets – 1 isn’t enoughConnected vs. Listening DescriptorsEcho Server: accept IllustratedEcho Server: Main LoopEcho Server: open_listenfdEcho Server: open_listenfd (cont)Echo Server: open_listenfd (socket)Echo Server: open_listenfd (initialize socket address)Echo Server: open_listenfd (bind)Echo Server: open_listenfd (listen)Echo Server: acceptEcho Server: Main RoutineEcho Server: Identifying the ClientEcho Server: echoRunning Echo Client/ServerIterative ServersFundamental Flaw of Iterative ServersConcurrent ServersPossible Mechanisms for Creating Concurrent FlowsEvent-Based Concurrent Servers Using I/O MultiplexingThe select FunctionMacros for Manipulating Set DescriptorsEvent-based Concurrent Echo ServerEvent-based Concurrent Server (cont)Slide 43Slide 44Slide 45Pro and Cons of Event-Based DesignsAttack #1Attack #2: Partial LinesFlaky ClientImplementing a Robust ServerRobust ServerRobust Server LoopConceptual ModelFor More InformationSlide 55GDB and RCSDebugging with gdbControlling Your Program With gdbExamining the State of Your ProgramVersion Control with RCSCreating RCS FilesChecking out filesVersionsMore information…Network ProgrammingJan 13, 2005TopicsProgrammer’s view of the InternetSockets interfaceWriting clients and serversConcurrency with I/O multiplexingDebugging With GDBVersion Control With RCSclass03.ppt15-441David A. MaltzSlides based on work by •Randy Bryant and the 15-213 crew•Geoff Langdale215-441, Spring 2005A Client-Server ExchangeClientprocessServerprocess1. Client sends request2. Server handlesrequest3. Server sends response4. Client handlesresponseResourceA server process and one or more client processesServer manages some resource.Server provides service by manipulating resource for clients.Note: clients and servers are processes running on hosts (can be the same or different hosts).315-441, Spring 2005Network ApplicationsAccess to Network via Program InterfaceSockets make network I/O look like filesCall system functions to control and communicateNetwork code handles issues of routing, segmentation.OSNetworkInterfaceClientAppl.SocketOS +NetworkAPIsOSNetworkInterfaceServerAppl.SocketOS +NetworkAPIsInternetClient MachineClient MachineServer MachineServer Machine415-441, Spring 2005Internet Connections (TCP/IP)Connection socket pair(128.2.194.242:3479, 208.216.181.15:80)Server(port 80)ClientClient socket address128.2.194.242:3479Server socket address208.216.181.15:80Client host address128.2.194.242 Server host address208.216.181.15Two common paradigms for clients and servers communicationDatagrams (UDP protocol SOCK_DGRAM)Connections (TCP protocol, SOCK_STREAM) Connections are point-to-point, full-duplex (2-way communication), and reliable. (TODAY’S TOPIC!)Note: 3479 is anephemeral port allocatedby the kernel Note: 80 is a well-known portassociated with Web servers515-441, Spring 2005ClientsExamples of client programsWeb browsers, ftp, telnet, sshHow does a client find the server?The IP address in the server socket address identifies the host (more precisely, an adaptor 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 known portsPort 7: Echo serverPort 23: Telnet serverPort 25: Mail serverPort 80: Web server615-441, Spring 2005Using Ports to Identify ServicesWeb server(port 80)Client hostServer host 128.2.194.242Echo server(port 7)Service request for128.2.194.242:80(i.e., the Web server)Web server(port 80)Echo server(port 7)Service request for128.2.194.242:7(i.e., the echo server)KernelKernelClientClient715-441, Spring 2005ServersServers are long-running processes (daemons).Created at boot-time (typically) 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.Port 7: echo serverPort 23: telnet serverPort 25: mail serverPort 80: HTTP serverA machine that runs a server process is also often referred to as a “server.”See /etc/services for a comprehensive list of the services available on a Linux machine.815-441, Spring 2005Client / ServerSessionOverview of the Sockets InterfaceClientServersocket socketbindlistenreadwritereadwriteConnectionrequestreadclosecloseEOFAwait connectionrequest fromnext clientopen_listenfdopen_clientfdacceptconnect915-441, Spring 2005SocketsWhat 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.1015-441, Spring 2005Socket Programming ClichesNetwork Byte OrderingNetwork is big-endian, host may be big- or little-endianFunctions work on 16-bit (short) and 32-bit (long) values htons() / htonl() : convert host byte order to network byte orderntohs() / ntohl(): convert network byte order to host byte orderUse these to convert network addresses, ports, …Structure CastsYou will see a lot of ‘structure casts’ struct sockaddr_in serveraddr; /* fill in serveraddr with an address */ … /* Connect takes (struct sockaddr *) as its second argument */ connect(clientfd, (struct sockaddr *) &serveraddr,sizeof(serveraddr)); …1115-441, Spring 2005Socket Programming Helpman is your friend (aka RTFM)man acceptman selectEtc. The manual page will tell you:What #include<> directives you need at the top of your source codeThe type of each argumentThe possible return valuesThe possible errors (in errno)1215-441, Spring 2005Socket Address StructuresGeneric socket address:For


View Full Document

CMU CS 15441 - Lecture

Documents in this Course
lecture

lecture

34 pages

lecture

lecture

38 pages

lecture

lecture

18 pages

lecture

lecture

28 pages

lecture

lecture

11 pages

lecture

lecture

10 pages

lecture

lecture

19 pages

Lecture 6

Lecture 6

43 pages

Exam

Exam

14 pages

lecture

lecture

38 pages

Debugging

Debugging

23 pages

lecture

lecture

60 pages

review

review

27 pages

lecture

lecture

12 pages

The Web

The Web

28 pages

Lecture

Lecture

40 pages

lecture

lecture

42 pages

lecture

lecture

9 pages

lecture

lecture

10 pages

lecture

lecture

49 pages

lecture

lecture

26 pages

Project

Project

5 pages

lecture

lecture

40 pages

lecture

lecture

9 pages

lecture

lecture

41 pages

lecture

lecture

32 pages

lecture

lecture

36 pages

lecture

lecture

34 pages

lecture

lecture

45 pages

lecture

lecture

26 pages

lecture

lecture

6 pages

lecture

lecture

51 pages

Project

Project

16 pages

lecture

lecture

44 pages

lecture

lecture

13 pages

lecture

lecture

42 pages

lecture

lecture

36 pages

Project

Project

13 pages

Project

Project

33 pages

lecture

lecture

43 pages

lecture

lecture

49 pages

Load more
Download Lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?