15-213 The course that gives CMU its Zip! Network Programming - - PowerPoint PPT Presentation

15 213
SMART_READER_LITE
LIVE PREVIEW

15-213 The course that gives CMU its Zip! Network Programming - - PowerPoint PPT Presentation

15-213 The course that gives CMU its Zip! Network Programming Network Programming Nov 21, 2002 Nov 21, 2002 Topics Topics Programmers view of the Internet (review) Sockets interface Writing clients and servers


slide-1
SLIDE 1 Network Programming Nov 21, 2002 Network Programming Nov 21, 2002 Topics Topics
  • Programmer’s view of the Internet (review)
  • Sockets interface
  • Writing clients and servers
✁✄✂✄☎✝✆✄✆✟✞✝✠☛✡✌☞✍☞☛✎ 15-213 “The course that gives CMU its Zip!”
slide-2
SLIDE 2 – 2 – 15-213, F’02 A Client-Server Transaction A Client-Server Transaction Client process Server process
  • 1. Client sends request
  • 2. Server
handles request
  • 3. Server sends response
  • 4. Client
handles response Resource Every network application is based on the client-server Every network application is based on the client-server model: model:
  • 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).
slide-3
SLIDE 3 – 3 – 15-213, F’02 A Programmer’s View of the Internet A Programmer’s View of the Internet
  • 1. Hosts are mapped to a set of 32-bit
  • 1. Hosts are mapped to a set of 32-bit IP addresses
IP addresses. .
  • 128.2.203.179
  • 2. The set of IP addresses is mapped to a set of
  • 2. The set of IP addresses is mapped to a set of
identifiers called Internet identifiers called Internet domain names domain names. .
  • 128.2.203.179 is mapped to www.cs.cmu.edu
  • 3. A process on one Internet host can communicate
  • 3. A process on one Internet host can communicate
with a process on another Internet host over a with a process on another Internet host over a connection connection. .
slide-4
SLIDE 4 – 4 – 15-213, F’02
  • 1. IP Addresses
  • 1. IP Addresses
32-bit IP addresses are stored in an 32-bit IP addresses are stored in an IP address IP address struct struct
  • IP addresses are always stored in memory in network byte
  • rder (big-endian byte order)
  • True in general for any integer transferred in a packet header
from one machine to another. E.g., the port number used to identify an Internet connection. ✏✒✑ ✓✕✔✗✖✕✘✗✙✕✔✒✘✗✖ ✚✒✛✒✛✗✙✕✘✗✜✒✜ ✜✒✖✒✙✕✢✗✣✒✖✕✢✗✙✕✘ ✑✒✏ ✜✒✖✒✙✕✢✗✣✒✖ ✤✕✔✦✥✗✚✒✛✒✛✗✙ ✧ ✢✒✔✗✜✒✤✕★✒✔✒✘✒✛ ✤✦✔✗✖ ✜✩✥✗✚✒✛✒✛✗✙✫✪ ✏✒✑ ✔✒✘✗✖✩✬✗✭✗✙✕✮ ✯✗✰✗✖✕✘ ✭✗✙✕✛✒✘✗✙ ✱✲✯✫✤✕★✴✳✒✘✒✔✒✛✗✤✕✚✒✔✶✵ ✑✒✏ ✷ ✪ Handy network byte-order conversion functions: ✸✺✹✼✻☛✽✺✾❀✿ convert ✾✼✻☛✽✼❁ ❂❃✽✺✹ from host to network byte order. ✸✺✹✼✻☛✽✺❄❀✿ convert ❄☛✸✺✻✼❅✼✹ ❂☛✽✺✹ from host to network byte order. ✽✺✹✼✻☛✸✺✾❀✿ convert ✾✼✻☛✽✼❁ ❂❃✽✺✹ from network to host byte order. ✽✺✹✼✻☛✸✺❄❀✿ convert ❄☛✸✺✻✼❅✼✹ ❂☛✽✺✹ from network to host byte order.
slide-5
SLIDE 5 – 5 – 15-213, F’02
  • 2. Domain Naming System (DNS)
  • 2. Domain Naming System (DNS)
The Internet maintains a mapping between IP addresses The Internet maintains a mapping between IP addresses and domain names in a huge worldwide distributed and domain names in a huge worldwide distributed database called database called DNS DNS. .
  • Conceptually, programmers can view the DNS database as a
collection of millions of host entry structures: Functions for retrieving host entries from DNS: Functions for retrieving host entries from DNS:
  • ❆❈❇❊❉✗❋❍●❊■❈❉❑❏❊▲❈▼❍◆✗❖P❇ : query key is a DNS domain name.
  • ❆❈❇❊❉✴❋❊●❊■◗❉✒❏❍▲❊◆❈❘◗❘❈❙
❚ query key is an IP address. ✏✒✑ ❯✕❱✫❲ ❳❑✭✗✜✒✖ ✘✒✔✗✖✒✙✕✰ ✜✒✖✒✙✕✢✗✣✒✖✕✢✗✙✕✘ ✑✒✏ ✜✒✖✒✙✕✢✴✣✒✖ ❳✒✭✗✜✒✖✕✘✒✔✗✖ ✧ ✣✕❳✒✚✗✙ ✑✕❳✕✥✗✔✒✚✕❨✗✘❈✪ ✏✒✑ ✭✗❩✒❩✒✤✒✣✒✤❬✚✗❭ ✛✒✭✕❨✗✚✗✤✕✔ ✔✒✚✕❨✗✘ ✭✗❩ ❳✒✭✗✜✒✖ ✑✒✏ ✣✕❳✒✚✗✙ ✑✒✑✕❳✕✥✗✚✗❭✒✤✕✚✗✜✕✘✗✜✫✪ ✏✒✑ ✔✒✢✗❭✒❭✒✳✒✖❬✘✗✙✩❨✫✤✕✔✒✚✗✖✕✘✒✛ ✚✗✙✒✙✕✚✒✰ ✭✗❩ ✛✒✭✕❨✗✚✗✤✕✔ ✔✒✚✕❨✗✘✗✜ ✑✒✏ ✤✕✔✗✖ ❳✕✥✗✚✒✛✒✛✗✙✒✖✕✰✕❪✗✘❫✪ ✏✒✑ ❳✒✭✗✜✒✖ ✚✒✛✒✛✗✙✕✘✗✜✒✜ ✖✕✰✕❪✗✘ ✱✲❴✗❵✕✥✫✓✩❱✗❛❝❜✫✵ ✑✒✏ ✤✕✔✗✖ ❳✕✥✫❭✕✘✒✔✒★✗✖✕❳❈✪ ✏✒✑ ❭✕✘✒✔✒★✗✖✕❳ ✭✗❩ ✚✒✔ ✚✒✛✒✛❞✙✕✘✗✜✒✜❈❡ ✤✕✔ ✯✗✰✗✖✕✘✗✜ ✑✒✏ ✣✦❳✒✚✗✙ ✑✒✑✕❳✕✥❢✚✒✛✒✛✗✙❣✥✫❭✒✤✒✜✒✖✫✪ ✏✒✑ ✔✒✢✗❭✒❭✒✳✒✖✕✘✗✙✩❨✫✤✕✔✒✚✗✖✕✘✒✛ ✚✗✙✒✙✕✚✒✰ ✭✗❩ ✤✕✔✕✥✗✚✒✛✒✛✗✙ ✜✒✖✒✙✕✢✗✣✒✖✒✜ ✑✒✏ ✷ ✪
slide-6
SLIDE 6 – 6 – 15-213, F’02
  • 3. Internet Connections
  • 3. Internet Connections
Connection socket pair (128.2.194.242:51213, 208.216.181.15:80) Server (port 80) Client Client socket address 128.2.194.242:51213 Server socket address 208.216.181.15:80 Client host address 128.2.194.242 Server host address 208.216.181.15 Clients and servers communicate by sending streams Clients and servers communicate by sending streams
  • f bytes over
  • f bytes over connections
connections. . Connections are point-to-point, full-duplex (2-way Connections are point-to-point, full-duplex (2-way communication), and reliable. communication), and reliable. Note: 51213 is an ephemeral port allocated by the kernel Note: 80 is a well-known port associated with Web servers
slide-7
SLIDE 7 – 7 – 15-213, F’02 Clients Clients Examples of client programs Examples of client programs
  • Web browsers,
❤ ❉✗✐ , ❉✫❇❈❥✫▼❊❇❊❉ , ■❈■✗❋ How does a client find the server? 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
slide-8
SLIDE 8 – 8 – 15-213, F’02 Using Ports to Identify Services Using Ports to Identify Services Web server (port 80) Client host Server host 128.2.194.242 Echo server (port 7) Service request for 128.2.194.242:80 (i.e., the Web server) Web server (port 80) Echo server (port 7) Service request for 128.2.194.242:7 (i.e., the echo server)

KernelKernelClientClient

slide-9
SLIDE 9 – 9 – 15-213, F’02 Servers Servers Servers are long-running processes (daemons). Servers 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 Each server waits for requests to arrive on a well-known port associated with a particular service. port associated with a particular service.
  • Port 7: echo server
  • Port 23: telnet server
  • Port 25: mail server
  • Port 80: HTTP server
A machine that runs a server process is also often A machine that runs a server process is also often referred to as a “server.” referred to as a “server.”
slide-10
SLIDE 10 – 10 – 15-213, F’02 Server Examples Server Examples Web server (port 80) Web server (port 80)
  • Resource: files/compute cycles (CGI programs)
  • Service: retrieves files and runs CGI programs on behalf of
the client FTP server (20, 21) FTP server (20, 21)
  • Resource: files
  • Service: stores and retrieve files
Telnet server (23) Telnet server (23)
  • Resource: terminal
  • Service: proxies a terminal on the server machine
Mail server (25) Mail server (25)
  • Resource: email “spool” file
  • Service: stores mail messages in spool file
See ❦☛❧ ✹✼♠ ❦ ❄ ❧ ❅☛♥✺❂✼♠ ❧ ❄ for a comprehensive list of the services available on a Linux machine.
slide-11
SLIDE 11 – 11 – 15-213, F’02 Sockets Interface Sockets Interface Created in the early 80’s as part of the original Berkeley Created in the early 80’s as part of the original Berkeley distribution of Unix that contained an early version of distribution of Unix that contained an early version of the Internet protocols. the Internet protocols. Provides a user-level interface to the network. Provides a user-level interface to the network. Underlying basis for all Internet applications. Underlying basis for all Internet applications. Based on client/server programming model. Based on client/server programming model.
slide-12
SLIDE 12 – 12 – 15-213, F’02 Overview of the Sockets Interface Overview of the Sockets Interface Client Server ✆✟♦✄✁✄♣✄q✝✎ ✆✟♦✄✁✄♣✄q✝✎ r✝s✄t✄✉ ✂ s ✆✄✎✟q t ☎✄✁✄✁✄q✟☞☛✎ ✈ s ♦✟✇✝✈✄q✄☎ ✉ ✂ s✄t q r ✈ s ♦✟✇✝✈✄q✄☎ ✉ ✂ s✄t q r ✈ s ♦✟✇✄①✝✈ s ✎✟q t ✁✄✂✄♦✝✆✟q ✈ s ♦✟✇✝✈✄q✄☎ ✉ ✂ s✄t q r ✁✄♦ t✄t q✄✁✝✎ ✈ s ♦✟✇✄①✝✈ s ✎✟q t ✁✄✂✄♦✝✆✟q Connection request EOF Await connection request from next client ✭✕❪✗✘❑✔✕✥✶❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛ ✭✕❪✗✘❑✔✕✥✶✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛
slide-13
SLIDE 13 – 13 – 15-213, F’02 Sockets Sockets What is a socket? 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 Clients and servers communicate with each by reading from and writing to socket descriptors. from and writing to socket descriptors. The main distinction between regular file I/O and socket The main distinction between regular file I/O and socket I/O is how the application “opens” the socket I/O is how the application “opens” the socket descriptors. descriptors.
slide-14
SLIDE 14 – 14 – 15-213, F’02 Socket Address Structures Socket Address Structures Generic socket address: Generic socket address:
  • For address arguments to
  • ✫▼❈▼❍❇
② ❉ , ❏P③✫▼❍❘ , and ◆ ②❈② ❇✫✐P❉⑤④
  • Necessary only because C did not have generic (
  • ❈③❈❘
⑦ ) pointers when the sockets interface was designed. Internet-specific socket address: Internet-specific socket address:
  • Must cast (
■⑧● ②❈⑨ ◆◗❘❈❘❈❙✗⑩P③⑧▼ ⑦ ) to ( ■✫● ②◗⑨ ◆❈❘❈❘◗❙ ⑦ ) for ②
  • ✫▼◗▼❊❇
② ❉ , ❏P③✫▼❊❘ , and ◆ ②❈② ❇✫✐P❉ . ✜✒✖✒✙✕✢✴✣✒✖ ✜✕✭✗✣✕✮✒✚✒✛✒✛✗✙ ✧ ✢✒✔✗✜❑✤✕★✒✔✒✘✒✛ ✜✕❳✒✭✗✙✒✖ ✜✕✚✕✥✫❩✕✚✕❨✫✤✒❭✕✰❈✪ ✏✒✑ ❪✫✙✕✭✗✖✕✭✗✣✕✭✗❭ ❩✕✚✕❨✫✤✒❭✕✰ ✑✒✏ ✣✕❳✒✚✴✙ ✜✕✚✕✥✗✛✒✚✗✖✕✚P❶❸❷✒❹✗❺✗✪ ✏✒✑ ✚✒✛✒✛✗✙✕✘✗✜✒✜ ✛✒✚✗✖✕✚❊❻ ✑✒✏ ✷ ✪ ✜✒✖✒✙✕✢✴✣✒✖ ✜✕✭✗✣✕✮✒✚✒✛✒✛✗✙✍✥✫✤✕✔ ✧ ✢✒✔✗✜✒✤✕★✒✔✒✘❑✛ ✜✕❳✒✭✗✙✒✖ ✜✒✤✕✔✕✥✫❩✕✚✕❨✫✤✒❭✕✰❈✪ ✏✒✑ ✚✒✛✒✛✗✙✕✘✗✜✒✜ ❩✕✚✕❨✫✤✒❭✕✰ ✱❼✚✗❭✩✬✗✚✒✰✗✜ ❴✗❵✕✥✫✓✩❱✗❛✒❜✫✵ ✑✒✏ ✢✒✔✗✜✒✤✕★✒✔✒✘❑✛ ✜✕❳✒✭✗✙✒✖ ✜✒✤✕✔✕✥✒❪✗✭✗✙✒✖✫✪ ✏✒✑ ❪✗✭✗✙✒✖ ✔✒✢✕❨ ✤✕✔ ✔✒✘✗✖✩✬✗✭✗✙✕✮ ✯✗✰✗✖✕✘ ✭✗✙✕✛✒✘✗✙ ✑✒✏ ✜✒✖✒✙✕✢✗✣✒✖ ✤✕✔✕✥✗✚✒✛✒✛✗✙ ✜✒✤✕✔✕✥✗✚✒✛✒✛✗✙✶✪ ✏✒✑ ✓✒❽ ✚✒✛✒✛✗✙ ✤✕✔ ✔✒✘✗✖✩✬✗✭✗✙✕✮ ✯✗✰✗✖✕✘ ✭✗✙✕✛✒✘✗✙ ✑✒✏ ✢✒✔✗✜✒✤✕★✒✔✒✘❑✛ ✣✕❳✒✚✗✙ ✜✒✤✕✔✕✥✫❾✕✘✗✙✕✭P❶❸❿✗❺✗✪ ✏✒✑ ❪✗✚✒✛ ✖✕✭ ✜✒✤✒❾✕✘✒✭✗❩➀✱❸✜✒✖✒✙✦✢✗✣✒✖ ✜✕✭✗✣✕✮✒✚✒✛✒✛✗✙➁✵ ✑✒✏ ✷ ✪
slide-15
SLIDE 15 – 15 – 15-213, F’02 Echo Client Main Routine Echo Client Main Routine ➂ ✤✕✔✗✣✒❭✕✢✒✛✒✘ ➃➄✣✒✜✕✚✕❪✒❪➅❻❸❳⑧➃ ✏✒✑ ✢✗✜✕✚✒★✒✘❊➆ ❻➇✏➄✘✗✣✕❳✒✭✗✣✒❭✒✤✕✘✒✔✗✖ ❳✒✭✗✜✒✖ ❪✗✭✴✙✒✖ ✑✒✏ ✤✕✔✗✖ ❨✗✚✗✤✕✔P✱➈✤✕✔✗✖ ✚✗✙✕★✗✣➉❡ ✣✕❳✒✚✗✙ ✑✒✑➊✚✗✙✕★✒➋✫✵ ✧ ✤✕✔✗✖ ✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛➌❡ ❪✗✭✗✙❑✖✫✪ ✣✕❳✒✚✗✙ ✑✕❳✒✭✗✜✒✖❈❡ ✯✗✢✗❩❊❶✲➍✒❴✗➎✒➏✗✓➐❱✗❛✫❺✗✪ ✙✒✤✕✭➄✥✫✖ ✙✒✤✕✭❈✪ ❳✒✭✗✜✒✖ ➑ ✚✗✙✕★✒➋➅❶❸❷✗❺✴✪ ❪✗✭✗✙✒✖ ➑ ✚✗✖✕✭✗✤➀✱❼✚✗✙✕★✒➋P❶❸➒✴❺✒✵✗✪ ✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛ ➑ ➓✕❪✗✘✒✔✕✥✶✣✒❭✒✤✕✘✒✔✴✖✒❩✕✛➅✱❼❳✒✭✗✜✒✖❈❡ ❪✗✭✗✙✒✖✗✵✗✪ ➔ ✤✕✭✕✥❞✙✕✘✒✚✒✛✗✤✕✔✗✤✒✖✩✯→✱➇➣✕✙✒✤✦✭❊❡ ✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛✫✵✗✪ ✬✗❳✗✤✒❭✕✘ ✱↔❵✒★✒✘✗✖✒✜➀✱✲✯✗✢✗❩❈❡ ➍✒❴✗➎❑➏✗✓✩❱✗❛❊❡ ✜✒✖✕✛✗✤✕✔✶✵ ↕❸➑ ❱✗➙✒➏✒➏✫✵ ✧ ➔ ✤✕✭✕✥❬✬✫✙✒✤✒✖✕✘✒✔➅✱❸✣✒❭✒✤✕✘✒✔✴✖✒❩✕✛➀❡ ✯✗✢✗❩❈❡ ✜✒✖✒✙❑❭✕✘✒✔P✱✲✯✗✢✗❩❢✵✒✵✗✪ ➔ ✤✕✭✕✥❞✙✕✘✒✚✒✛✗❭✒✤✕✔✒✘✕✯→✱➇➣✕✙❑✤✕✭➀❡ ✯✗✢✗❩❈❡ ➍✒❴✗➎✒➏✗✓✩❱✗❛✫✵✗✪ ❵✕❪✗✢✗✖✒✜❊✱✲✯✗✢✗❩➉❡ ✜✒✖✕✛❑✭✒✢✗✖❢✵✗✪ ✷ ➛ ❭✕✭✗✜✕✘P✱➈✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛✶✵✗✪ ✘✒➜✗✤✒✖❊✱❸➝✗✵✗✪ ✷
slide-16
SLIDE 16 – 16 – 15-213, F’02 Echo Client: Echo Client: ✤✕✔✗✖ ✭✕❪✴✘✒✔✕✥✶✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛➅✱❸✣✕❳✒✚✗✙ ✑✕❳✒✭✗✜✒✖✕✔✒✚✕❨✗✘❊❡ ✤✕✔✗✖ ❪✗✭✗✙✒✖✗✵ ✧ ✤✕✔✗✖ ✣✒❭✒✤✦✘✒✔✗✖✒❩✕✛➉✪ ✜✒✖✒✙✕✢✗✣✒✖ ❳❑✭✗✜✒✖✕✘✒✔✗✖ ✑✦❳✕❪❊✪ ✜✒✖✒✙✕✢✗✣✒✖ ✜✕✭✴✣✕✮✒✚✒✛✒✛✗✙➞✥✫✤✕✔ ✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙✶✪ ✤✒❩ ✱✒✱➟✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛ ➑ ✜✕✭✗✣✕✮✒✘✗✖❊✱➠❴✗❵✕✥✫✓✩❱✗❛✒❜❊❡ ❲✕➓ ➛✒➡ ✥✫❲✕❜ ➔ ❛✕❴✒➍P❡ ➝✗✵✒✵ ➢ ➝✗✵ ✙✕✘✗✖✕✢✗✙✕✔ ✳✒❷✫✪ ✏✒✑ ✣✕❳✒✘✗✣✕✮ ✘✗✙✒✙✕✔✒✭ ❩✕✭✗✙ ✣✕✚✒✢✗✜✕✘ ✭✗❩ ✘✗✙✒✙✕✭✗✙ ✑✒✏ ✏✒✑ ❵✗✤✒❭✒❭ ✤✕✔ ✖✕❳✒✘ ✜✕✘✗✙✕➋✒✘✴✙❈➤➇✜ ✓✒❽ ✚✒✛✒✛✗✙✕✘❞✜✒✜ ✚✒✔✒✛ ❪✗✭✗✙✒✖ ✑✒✏ ✤✒❩ ✱✒✱❼❳✦❪ ➑ ★✒✘✗✖✕❳✒✭✗✜✒✖✩✯✗✰✒✔✒✚✕❨✗✘➥✱❼❳✒✭✗✜✒✖✕✔✒✚✕❨✗✘✫✵✒✵ ➑✒➑ ❱✗➙✒➏✒➏✫✵ ✙✕✘✗✖✕✢✗✙✕✔ ✳✒➒✫✪ ✏✒✑ ✣✕❳✒✘✗✣✕✮ ❳✕✥✫✘✗✙✒✙✕✔✒✭ ❩✕✭✗✙ ✣✕✚✒✢✗✜✕✘ ✭✗❩ ✘✗✙✒✙✕✭✗✙ ✑✒✏ ✯✫❾✦✘✗✙✕✭➅✱✒✱❸✣✕❳✒✚✗✙ ✑✗✵ ➣➊✜✕✘✗✙✦➋✒✘✗✙✕✚✒✛✒✛✗✙➉❡ ✜✒✤✒❾✕✘✒✭✗❩➦✱❸✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙❢✵✒✵✴✪ ✜✕✘✗✙✕➋✒✘✗✙✦✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥✫❩✕✚✕❨✫✤✒❭✕✰ ➑ ❴✗❵✕✥✫✓✩❱✗❛✒❜❈✪ ✯✫✣✦✭✕❪✗✰➅✱✒✱❸✣✕❳✒✚✗✙ ✑✗✵✩❳✕❪✫✳✕➧✒❳✕✥❢✚❑✛✒✛✗✙➉❡ ✱❸✣✕❳❑✚✗✙ ✑✗✵✒➣➨✜✕✘✗✙✦➋✒✘✗✙✕✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥✗✚✒✛✒✛✗✙❫❻➇✜✩✥✗✚✒✛✒✛✗✙❈❡ ❳✕❪✫✳✕➧✒❳✕✥✫❭✕✘✒✔✒★✗✖✕❳✫✵✗✪ ✜✕✘✗✙✕➋✒✘✗✙✦✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥✒❪✗✭✗✙✒✖ ➑ ❳✗✖✕✭✒✔✗✜❊✱✲❪✗✭✗✙✒✖✗✵✗✪ ✏✒✑ ❛✗✜✒✖✕✚✕✯✫❭✒✤✒✜✕❳ ✚ ✣✕✭✒✔✒✔✒✘✴✣✒✖✒✤✕✭✒✔ ✬✫✤✒✖✕❳ ✖❬❳✒✘ ✜✕✘✗✙✕➋✒✘✗✙ ✑✒✏ ✤✒❩ ✱❸✣✕✭✒✔❑✔✒✘✗✣✒✖❊✱➟✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛➀❡ ✱➩❲✩❴ ✑✗✵ ➣➊✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙❫❡ ✜✒✤✒❾✕✘✒✭✗❩❊✱❸✜✕✘✗✙✕➋❑✘✗✙✕✚✒✛✒✛✗✙❢✵✒✵ ➢ ➝✗✵ ✙✕✘✗✖✕✢✗✙✦✔ ✳✒❷✫✪ ✙✕✘✗✖✕✢✴✙✕✔ ✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛➉✪ ✷ This function opens a connection from the client to the server at ❳✒✭✗✜✒✖✕✔✒✚✕❨✗✘❊➆❼❪✗✭✗✙✒✖
slide-17
SLIDE 17 – 17 – 15-213, F’02 Echo Client: Echo Client: ✤✕✔✗✖ ✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛➉✪ ✏✒✑ ✜✕✭✗✣✕✮✒✘✗✖ ✛✒✘✗✜✒✣✒✙✒✤✩❪✫✖✕✭✗✙ ✑✒✏ ✤✒❩ ✱✒✱➟✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛ ➑ ✜✕✭✗✣✕✮✒✘✗✖❊✱✲❴✗❵✕✥✫✓✩❱✗❛✒❜❊❡ ❲✕➓ ➛✒➡ ✥✫❲✕❜ ➔ ❛✕❴✒➍P❡ ➝✗✵✒✵ ➢ ➝✗✵ ✙✕✘✴✖✕✢✗✙✕✔ ✳✒❷✫✪ ✏✒✑ ✣✕❳✒✘✗✣✕✮ ✘✗✙✒✙✕✔✒✭ ❩✕✭✗✙ ✣✕✚✒✢✗✜✕✘ ✭✗❩ ✘✗✙✒✙✕✭✗✙ ✑✒✏ ❻✒❻✒❻ ✱✲❨✗✭✗✙✕✘✫✵ creates a socket descriptor on the client. creates a socket descriptor on the client.
  • ➫P➭✗⑩⑤➯✗➲◗➳❊➵ : indicates that the socket is associated with Internet
protocols.
  • ➸✫➺❊➻⑧➼✫⑩P➸❈➵⑧➽❈➳✫➫◗➾ : selects a reliable byte stream connection.
slide-18
SLIDE 18 – 18 – 15-213, F’02 Echo Client: Echo Client: The client then builds the server’s Internet address. The client then builds the server’s Internet address. ✤✕✔✗✖ ✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛➉✪ ✏✒✑ ✜✕✭✗✣✕✮✒✘✗✖ ✛✒✘✗✜❝✣✒✙✒✤➐❪✫✖✕✭✗✙ ✑✒✏ ✜✒✖✒✙✕✢✴✣✒✖ ❳✒✭✗✜✒✖✕✘✒✔✗✖ ✑✕❳✕❪❊✪ ✏✒✑ ❯✕❱✫❲ ❳✒✭✗✜✒✖ ✘❝✔✗✖❑✙✕✰ ✑✒✏ ✜✒✖✒✙✕✢✴✣✒✖ ✜✕✭✗✣✕✮✒✚✒✛✒✛✗✙✍✥✫✤✕✔ ✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙✶✪ ✏✒✑ ✜✕✘✗✙✕➋✒✘✗✙✗➚✕✜ ✓✒❽ ✚✒✛✒✛✗✙✕✘✗✜✒✜ ✑✒✏ ❻❑❻✒❻ ✏✒✑ ❩✒✤✒❭✒❭ ✤✦✔ ✖✕❳✒✘ ✜✕✘✗✙✕➋✒✘✗✙❈➤➇✜ ✓✒❽ ✚✒✛✒✛✗✙✕✘✗✜✒✜ ✚✒✔✒✛ ❪✗✭✗✙✒✖ ✑✒✏ ✤✒❩ ✱✒✱❼❳✕❪ ➑ ★✒✘✗✖✕❳✒✭✗✜✒✖✩✯✗✰✒✔✒✚✕❨✗✘➪✱❼❳✒✭✗✜✒✖✕✔✒✚✕❨✗✘✫✵✒✵ ➑✒➑ ❱✗➙✒➏✒➏✫✵ ✙✕✘✗✖✦✢✗✙✕✔ ✳✒➒✫✪ ✏✒✑ ✣✕❳✒✘✗✣✕✮ ❳✕✥✫✘✗✙✒✙✕✔✒✭ ❩✕✭✗✙ ✣✕✚✒✢✗✜✕✘ ✭✗❩ ✘✗✙✒✙✕✭✗✙ ✑✒✏ ✯✫❾✦✘✗✙✕✭➅✱✒✱❸✣✕❳✒✚✗✙ ✑✗✵ ➣➄✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙➉❡ ✜✒✤✒❾✦✘✒✭✗❩➀✱❸✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙❢✵❑✵✗✪ ✜✕✘✗✙✦➋✒✘✗✙✕✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥✫❩✕✚✕❨✫✤✒❭✕✰ ➑ ❴✗❵✕✥✫✓✩❱✗❛✒❜❈✪ ✯✫✣✦✭✕❪✗✰➅✱✒✱❸✣✕❳✒✚✗✙ ✑✗✵✩❳✕❪✫✳✕➧✒❳✕✥❝✚✒✛✒✛✗✙➉❡ ✱❸✣✕❳✒✚✗✙ ✑✗✵✒➣➶✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥✗✚❑✛✒✛✗✙➉❻➇✜✩✥✗✚✒✛✒✛✗✙❈❡ ❳✕❪✫✳✕➧✒❳✕✥✫❭✕✘✒✔✒★✗✖✕❳✫✵✗✪ ✜✕✘✗✙✦➋✒✘✗✙✕✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥✒❪✗✭✗✙✒✖ ➑ ❳✗✖✕✭✒✔✗✜➀✱✲❪✗✭✗✙✒✖✴✵✗✪
slide-19
SLIDE 19 – 19 – 15-213, F’02 Echo Client: Echo Client: Finally the client creates a connection with the server. Finally the client creates a connection with the server.
  • Client process suspends (blocks) until the connection is created.
  • After resuming, the client is ready to begin exchanging messages
with the server via Unix I/O calls on descriptor ■✫● ②❈⑨❊❤ ❘ ④ ✤✕✔✴✖ ✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛➉✪ ✏✒✑ ✜✕✭✗✣✕✮✒✘✗✖ ✛✒✘✗✜✒✣❑✙✒✤✩❪✫✖✕✭✗✙ ✑✒✏ ✜✒✖✒✙✦✢✗✣✒✖ ✜✕✭✗✣✕✮✒✚✒✛✒✛✗✙✍✥✫✤✕✔ ✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙✶✪ ✏✒✑ ✜✕✘✗✙✕➋✒✘✗✙ ✚❑✛✒✛✗✙✕✘✗✜✒✜ ✑✒✏ ✖✕✰✕❪✗✘✒✛❑✘✗❩ ✜✒✖✒✙✕✢✗✣✒✖ ✜✕✭✗✣✕✮✒✚✒✛✒✛✗✙ ❲✩❴❊✪ ✏✒✑ ★❑✘✒✔✒✘✗✙✒✤✒✣ ✜✕✭✴✣✕✮✒✚✒✛✒✛✗✙ ✑✒✏ ❻❑❻✒❻ ✏✒✑ ❛✗✜✒✖✕✚✦✯✫❭✒✤✒✜✕❳ ✚ ✣✕✭✒✔✒✔✒✘✗✣✒✖✒✤✕✭✒✔ ✬✫✤✒✖✕❳ ✖❬❳✒✘ ✜✕✘✗✙✕➋✒✘✗✙ ✑✒✏ ✤✒❩ ✱❸✣✕✭✒✔✒✔✒✘✗✣✒✖❊✱➟✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛➦❡ ✱❸❲✩❴ ✑✗✵✒➣➊✜✕✘✗✙✕➋✒✘✗✙✦✚✒✛✒✛✗✙➉❡ ✜✒✤✒❾✕✘✒✭✗❩➀✱❸✜✕✘✴✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙❢✵✒✵ ➢ ➝✗✵ ✙✕✘✗✖✕✢✗✙✕✔ ✳✒❷✫✪ ✙✦✘✗✖✕✢✗✙✕✔ ✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛❫✪ ✷
slide-20
SLIDE 20 – 20 – 15-213, F’02 Echo Server: Main Routine Echo Server: Main Routine ✤✕✔✗✖ ❨✗✚✗✤✕✔P✱➟✤✕✔✗✖ ✚✗✙✕★✗✣❫❡ ✣✕❳✒✚✗✙ ✑✒✑➊✚✗✙✕★✒➋⑧✵ ✧ ✤✕✔✗✖ ❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛➌❡ ✣✕✭✒✔✒✔✗❩✕✛➀❡ ❪✗✭✗✙✒✖❈❡ ✣✒❭✒✤✦✘✒✔✗✖✒❭✕✘✒✔➉✪ ✜❑✖✒✙✕✢✗✣✒✖ ✜✕✭✗✣✕✮✒✚✒✛✒✛✗✙✍✥✫✤✕✔ ✣✒❭✒✤✕✘✒✔✗✖✕✚✒✛✒✛✗✙✶✪ ✜❑✖✒✙✕✢✗✣✒✖ ❳✒✭✗✜✒✖✕✘✒✔✗✖ ✑✕❳✕❪❊✪ ✣✕❳✒✚✗✙ ✑➊❳✒✚✒✛✒✛✗✙✩❪➦✪ ❪✗✭✗✙✒✖ ➑ ✚✗✖✕✭✗✤➦✱❼✚✗✙✕★✒➋P❶❸❷✗❺✒✵✗✪ ✏✒✑ ✖✕❳✒✘ ✜✕✘✗✙✕➋✒✘✗✙ ❭✒✤✒✜✒✖✕✘✒✔✗✜ ✭✒✔ ✚ ❪✗✭✗✙✒✖ ❪✗✚✗✜✒✜✕✘✒✛ ✭✒✔ ✖✕❳❝✘ ✣✕✭✕❨✒❨✗✚✒✔✒✛ ❭✒✤✕✔✒✘ ✑✒✏ ❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛ ➑ ✭✕❪✗✘✒✔✕✥❞❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛➅✱✲❪✗✭✗✙✒✖✴✵✗✪ ✬✗❳✗✤✒❭✕✘ ✱❸❷✗✵ ✧ ✣✒❭✒✤✕✘✒✔✗✖✒❭✕✘✒✔ ➑ ✜✒✤✒❾✕✘✒✭✗❩➀✱❸✣✒❭✒✤✕✘✒✔✗✖✦✚✒✛✒✛✗✙❢✵✗✪ ✣✕✭✒✔✒✔✗❩✕✛ ➑ ❴✫✣✒✣✕✘✕❪✫✖❊✱➹❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛❊❡ ✱➩❲✩❴ ✑✗✵✒➣➊✣✒❭✒✤✕✘✒✔✗✖✕✚✒✛✒✛✗✙➉❡ ➣➊✣✒❭✒✤✕✘✒✔✗✖✒❭✕✘✒✔❞✵✗✪ ❳✕❪ ➑ ➘✒✘✗✖✕❳✒✭✗✜✒✖✩✯✗✰✒✚✒✛✒✛✗✙➌✱✒✱❸✣✕✭✒✔✗✜✒✖ ✣✕❳❑✚✗✙ ✑✗✵✒➣➊✣✒❭✒✤✕✘✒✔✗✖✕✚✒✛✒✛✗✙➉❻➇✜❑✤✕✔✕✥❢✚✒✛✒✛✗✙❈❻➇✜✩✥❝✚✒✛✒✛✗✙❈❡ ✜✒✤✒❾✕✘✒✭✗❩❊✱❸✣✒❭✒✤✕✘❑✔✗✖✕✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥❢✚✒✛❑✛✗✙❈❻➇✜✩✥❢✚✒✛✒✛✗✙✗✵✫❡ ❴✗❵✕✥✫✓✩❱✗❛✒❜✫✵✗✪ ❳✒✚✒✛✒✛✗✙✩❪ ➑ ✤✕✔✒✘✗✖✩✥✗✔✗✖✕✭✒✚➅✱❸✣✒❭✒✤✕✘✒✔✗✖✦✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥✗✚✒✛✒✛✗✙❢✵✴✪ ❪✫✙✒✤✕✔✗✖✒❩❊✱➇➃✕✜✕✘✗✙✕➋✒✘✗✙ ✣✕✭✒✔✒✔✒✘✗✣✒✖✕✘✒✛ ✖✕✭ ➴✒✜ ✱❸➴✒✜✗✵✦➷➬✔✫➃✫❡ ❳✕❪✫✳✕➧✒❳✕✥✗✔✒✚✕❨✗✘❊❡ ❳✒✚✒✛✒✛✗✙✩❪❫✵✗✪ ✘✗✣✕❳✒✭P✱➟✣✕✭✒✔✒✔✗❩✕✛❞✵✗✪ ➛ ❭✕✭✗✜✕✘P✱➟✣✕✭✒✔✒✔✗❩✕✛❞✵✗✪ ✷ ✷
slide-21
SLIDE 21 – 21 – 15-213, F’02 Echo Server: Echo Server: ✤✕✔✗✖ ✭✕❪✗✘✒✔✕✥✶❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛➪✱❸✤✕✔✗✖ ❪✗✭✗✙✒✖✗✵ ✧ ✤✕✔✗✖ ❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛➌❡ ✭✕❪✫✖✕➋✒✚✗❭➊➑✗❷⑧✪ ✜❑✖✒✙✕✢✗✣✒✖ ✜✕✭✗✣✕✮✒✚✒✛✒✛✗✙✍✥✫✤✕✔ ✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙✶✪ ✏✒✑ ➛ ✙✦✘✒✚✗✖✕✘ ✚ ✜✕✭✗✣✕✮✒✘✗✖ ✛✒✘✗✜✒✣✒✙✒✤✩❪✫✖✕✭✗✙ ✑✒✏ ✤✒❩ ✱✒✱➟❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛ ➑ ✜✕✭✗✣✕✮✒✘✗✖❊✱✲❴✗❵✕✥✫✓✩❱✗❛✒❜❊❡ ❲✕➓ ➛✒➡ ✥✫❲✕❜ ➔ ❛✕❴✒➍P❡ ➝✗✵✒✵ ➢ ➝✗✵ ✙✕✘✗✖✕✢✗✙✕✔ ✳✒❷✫✪ ✏✒✑ ❛✗❭❑✤✩❨✫✤✕✔✒✚✗✖✕✘✗✜ ➃➇❴✗✛✒✛✗✙✕✘✗✜✒✜ ✚✗❭✒✙✕✘✒✚✒✛✒✰ ✤✕✔ ✢✗✜✕✘✫➃ ✘✗✙✒✙✕✭✗✙ ❩✒✙✕✭✕❨ ✯✫✤✕✔✒✛❊❻ ✑✒✏ ✤✒❩ ✱➟✜✕✘✗✖✒✜✕✭✗✣✕✮✒✭✕❪✫✖➦✱❸❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛➀❡ ❲✕➓✒➏✕✥✫❲✕➓ ➛✒➡ ❛✒❜❊❡ ❲✕➓✕✥ ➔ ❛❑➙✗❲✕❛✕❴✗❯✒❯ ➔ ❡ ✱❸✣✕✭✒✔✗✜✒✖ ➋✒✭✗✤✕✛ ✑✗✵✒➣➄✭✕❪✫✖✕➋✒✚✗❭ ❡ ✜✒✤✒❾✕✘✒✭✗❩➀✱➩✤✕✔✗✖❢✵✒✵ ➢ ➝✗✵ ✙✕✘✗✖✕✢✗✙✕✔ ✳✒❷✫✪ ❻✒❻✒❻ ✱✲❨✗✭✗✙✕✘✫✵
slide-22
SLIDE 22 – 22 – 15-213, F’02 Echo Server: (cont) Echo Server: (cont) ❻❑❻✒❻ ✏✒✑ ➏✗✤✒✜✒✖✕✘✒✔✗❩✕✛ ✬✫✤✒❭✒❭ ✯✗✘ ✚✒✔ ✘✒✔✒✛✕❪✗✭✗✤✕✔✗✖ ❩✕✭✗✙ ✚✗❭✒❭ ✙✕✘❝➮✒✢✒✘✗✜❑✖✒✜ ✖✕✭ ❪✗✭✗✙✒✖ ✭✒✔ ✚✒✔✒✰ ✓✒❽ ✚✒✛✒✛✗✙✕✘✗✜✒✜ ❩✕✭✗✙ ✖✕❳✗✤✒✜ ❳✒✭✗✜✒✖ ✑✒✏ ✯✫❾✕✘✗✙✕✭➅✱✒✱❸✣✕❳✒✚✗✙ ✑✗✵ ➣➄✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙➉❡ ✜✒✤✒❾✦✘✒✭✗❩➀✱❸✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙❢✵❑✵✗✪ ✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥✫❩✕✚✕❨✫✤✒❭✕✰ ➑ ❴✗❵✕✥✫✓✩❱✗❛✒❜❈✪ ✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥❝✚✒✛✒✛✗✙❈❻➇✜✩✥❢✚✒✛✒✛✗✙ ➑ ❳✴✖✕✭✒✔✗❭➀✱❸✓✩❱✒❴✗❯✒❯ ➔ ✥✒❴✒❱✗➱✫✵✗✪ ✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥✒❪✗✭✗✙✒✖ ➑ ❳✗✖✕✭✒✔✗✜❊✱✒✱❼✢✒✔✗✜✒✤✕★✒✔✒✘✒✛ ✜✕❳✒✭✴✙✒✖✗✵➇❪✗✭✗✙✒✖✗✵✗✪ ✤✒❩ ✱✲✯✫✤✕✔✒✛P✱➟❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛➦❡ ✱❸❲✩❴ ✑✗✵✒➣➊✜✕✘✗✙✕➋✒✘✗✙✦✚✒✛✒✛✗✙➉❡ ✜✒✤✒❾✕✘✒✭✗❩➀✱❸✜✕✘✴✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙❢✵✒✵ ➢ ➝✗✵ ✙✕✘✗✖✕✢✗✙✕✔ ✳✒❷✫✪ ✏✒✑ ➍✗✚❑✮✒✘ ✤✒✖ ✚ ❭✒✤✒✜✒✖✕✘✒✔✗✤✕✔✒★ ✜✕✭✗✣✕✮✒✘✗✖ ✙✕✘✒✚✒✛✒✰ ✖✕✭ ✚✗✣✒✣✕✘✕❪✫✖ ✣✦✭✒✔✒✔✒✘✗✣✒✖✒✤✕✭✒✔ ✙✕✘✒➮✒✢✒✘✗✜✒✖✒✜ ✑✒✏ ✤✒❩ ✱❸❭✒✤✒✜✒✖✕✘✒✔P✱➹❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛❊❡ ➏✗✓✒❲✕❜✒❛✕❱✗✃✫✵ ➢ ➝✗✵ ✙✕✘✗✖✕✢✗✙✕✔ ✳✒❷✫✪ ✙✕✘✗✖✕✢✗✙✕✔ ❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛❫✪ ✷
slide-23
SLIDE 23 – 23 – 15-213, F’02 creates a socket descriptor on the server. creates a socket descriptor on the server.
  • ➫P➭✗⑩⑤➯✗➲◗➳❊➵ : indicates that the socket is associated with Internet
protocols.
  • ➸✫➺❊➻⑧➼✫⑩P➸❈➵⑧➽❈➳✫➫◗➾ : selects a reliable byte stream connection.
Echo Server: Echo Server: ✤✕✔✗✖ ❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛➉✪ ✏✒✑ ❭✒✤✒✜✒✖✕✘✒✔✗✤✕✔✒★ ✜✕✭✗✣✕✮✒✘✗✖ ✛✒✘✗✜✒✣✒✙✒✤✩❪✫✖✕✭✗✙ ✑✒✏ ✏✒✑ ➛ ✙✕✘✒✚✗✖✕✘ ✚ ✜✕✭✗✣✕✮✒✘✗✖ ✛✒✘✗✜✒✣✒✙✒✤✩❪✫✖✕✭✗✙ ✑✒✏ ✤✒❩ ✱✒✱➟❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛ ➑ ✜✕✭✗✣✕✮✒✘✗✖❊✱✲❴✗❵✕✥✫✓✩❱✗❛✒❜❊❡ ❲✕➓ ➛✒➡ ✥✫❲✕❜ ➔ ❛✕❴✒➍P❡ ➝✗✵✒✵ ➢ ➝✗✵ ✙✕✘✗✖✕✢✗✙✕✔ ✳✒❷✫✪
slide-24
SLIDE 24 – 24 – 15-213, F’02 Echo Server: Echo Server: The socket can be given some attributes. The socket can be given some attributes. Handy trick that allows us to rerun the server Handy trick that allows us to rerun the server immediately after we kill it. immediately after we kill it.
  • Otherwise we would have to wait about 15 secs.
  • Eliminates “Address already in use” error from
❏P③✫▼❊❘ ❐✒❒P④ Strongly suggest you do this for all your servers to Strongly suggest you do this for all your servers to simplify debugging. simplify debugging. ❻❑❻✒❻ ✏✒✑ ❛✗❭✒✤✩❨✫✤✕✔❑✚✗✖✕✘✗✜ ➃➇❴✗✛✒✛✗✙✕✘✗✜✒✜ ✚✗❭✒✙✕✘✒✚✒✛✒✰ ✤✕✔ ✢✗✜✕✘✫➃ ✘✗✙✒✙✕✭✗✙ ❩✒✙✕✭✕❨ ✯✫✤✕✔✒✛P✱➇✵✫❻ ✑✒✏ ✤✒❩ ✱➩✜✕✘✗✖✒✜✕✭✗✣✕✮✒✭✕❪✫✖➀✱➈❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛❊❡ ❲✕➓✒➏✕✥✫❲✕➓ ➛✒➡ ❛✒❜❊❡ ❲✕➓✕✥ ➔ ❛✒➙✗❲✕❛✕❴✗❯✒❯ ➔ ❡ ✱❸✣✕✭✒✔✗✜✒✖ ➋✒✭✗✤✕✛ ✑✗✵✒➣✕✭✕❪✫✖✕➋❑✚✗❭ ❡ ✜✒✤✒❾✕✘✒✭✗❩➀✱❸✤✕✔✴✖✗✵✒✵ ➢ ➝✗✵ ✙✕✘✗✖✕✢✗✙✕✔ ✳✒❷✫✪
slide-25
SLIDE 25 – 25 – 15-213, F’02 Echo Server: (initialize socket address) Echo Server: (initialize socket address) Next, we initialize the socket with the server’s Internet Next, we initialize the socket with the server’s Internet address (IP address and port) address (IP address and port) IP IP addr addr and port stored in network (big- and port stored in network (big-endian endian) byte order ) byte order
  • ❋P❉⑧●✫▼❊❥
❐✒❒ converts longs from host byte order to network byte
  • rder.
  • ❋P❉⑧●✫▼P■
❐✒❒ convers shorts from host byte order to network byte
  • rder.
✜✒✖✒✙✦✢✗✣✒✖ ✜✕✭✗✣✕✮✒✚✒✛✒✛✗✙✍✥✫✤✕✔ ✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙✶✪ ✏✒✑ ✜✕✘✗✙✕➋✒✘✗✙❈➤➇✜ ✜✕✭✗✣✕✮✒✘✗✖ ✚❑✛✒✛✗✙ ✑✒✏ ❻❑❻✒❻ ✏✒✑ ❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛ ✬✫✤✒❭✒❭ ✯✗✘ ✚✒✔ ✘✒✔✒✛✕❪✗✭✗✤✕✔✗✖ ❩✕✭✗✙ ✚✗❭✒❭ ✙✕✘❝➮✒✢✒✘✗✜❑✖✒✜ ✖✕✭ ❪✗✭✗✙✒✖ ✭✒✔ ✚❑✔✒✰ ✓✒❽ ✚✒✛✒✛✗✙✕✘✗✜✒✜ ❩✕✭✗✙ ✖✕❳✗✤✒✜ ❳✒✭❞✜✒✖ ✑✒✏ ✯✫❾✕✘✗✙✕✭➅✱✒✱❸✣✕❳✒✚✗✙ ✑✗✵ ➣➄✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙➉❡ ✜✒✤✒❾✦✘✒✭✗❩➀✱❸✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙❢✵❑✵✗✪ ✜✦✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥✫❩✕✚✕❨✫✤✒❭✕✰ ➑ ❴✗❵✕✥✫✓✩❱✗❛✒❜❈✪ ✜✦✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥❝✚✒✛✒✛✗✙❈❻➇✜✩✥❢✚✒✛✒✛✗✙ ➑ ❳✴✖✕✭✒✔✗❭➀✱❸✓✩❱✒❴✗❯✒❯ ➔ ✥✒❴✒❱✗➱✫✵✗✪ ✜✦✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥✒❪✗✭✗✙✒✖ ➑ ❳✗✖✕✭✒✔✗✜❊✱✒✱❼✢✒✔✗✜✒✤✕★✒✔✒✘✒✛ ✜✕❳✒✭✴✙✒✖✗✵➇❪✗✭✗✙✒✖✗✵✗✪
slide-26
SLIDE 26 – 26 – 15-213, F’02 Echo Server: Echo Server: associates the socket with the socket address we associates the socket with the socket address we just created. just created. ✤✕✔✗✖ ❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛➉✪ ✏✒✑ ❭✒✤✒✜✒✖✕✘✒✔✗✤✕✔✒★ ✜✕✭✗✣✦✮✒✘✗✖ ✑✒✏ ✜✒✖✒✙✕✢✴✣✒✖ ✜✕✭✗✣✕✮✒✚✒✛✒✛✗✙✍✥✫✤✕✔ ✜✕✘✗✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙✶✪ ✏✒✑ ✜✕✘✗✙✕➋✒✘✗✙✗➚✕✜ ✜✕✭✗✣✕✮✒✘✗✖ ✚❑✛✒✛✗✙ ✑✒✏ ❻❑❻✒❻ ✏✒✑ ❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛ ✬✫✤✒❭✒❭ ✯✗✘ ✚✒✔ ✘✒✔✒✛✕❪✗✭✗✤✕✔✗✖ ❩✕✭✗✙ ✚✗❭✒❭ ✙✕✘❝➮✒✢✒✘✗✜❑✖✒✜ ✖✕✭ ❪✗✭✗✙✒✖ ✭✒✔ ✚❑✔✒✰ ✓✒❽ ✚✒✛✒✛✗✙✕✘✗✜✒✜ ❩✕✭✗✙ ✖✕❳✗✤✒✜ ❳✒✭❞✜✒✖ ✑✒✏ ✤❑❩ ✱✲✯✫✤✕✔✒✛P✱➟❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛➦❡ ✱❸❲✩❴ ✑✗✵✒➣➊✜✕✘✗✙✕➋✒✘✗✙✦✚✒✛✒✛✗✙➉❡ ✜✒✤✒❾✕✘✒✭✗❩➀✱❸✜✕✘✴✙✕➋✒✘✗✙✕✚✒✛✒✛✗✙❢✵✒✵ ➢ ➝✗✵ ✙✕✘✗✖✕✢✗✙✕✔ ✳✒❷✫✪
slide-27
SLIDE 27 – 27 – 15-213, F’02 Echo Server: Echo Server: indicates that this socket will accept indicates that this socket will accept connection ( connection ( ) requests from clients. ) requests from clients. We’re finally ready to enter the main server loop that We’re finally ready to enter the main server loop that accepts and processes client connection requests. accepts and processes client connection requests. ✤✕✔✗✖ ❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛➉✪ ✏✒✑ ❭✒✤✒✜✒✖✕✘✒✔✗✤✕✔✒★ ✜✕✭✗✣✕✮✒✘✗✖ ✑✒✏ ❻❑❻✒❻ ✏✒✑ ➍✗✚✒✮✒✘ ✤✒✖ ✚ ❭✒✤✒✜✒✖✕✘✒✔✗✤✕✔✒★ ✜✕✭✗✣✕✮✒✘✗✖ ✙✕✘✒✚❝✛✒✰ ✖✕✭ ✚✗✣✒✣✕✘✕❪✫✖ ✣✕✭✒✔✒✔✒✘✗✣✒✖✒✤✕✭✒✔ ✙✕✘✒➮✒✢✒✘✗✜✒✖✒✜ ✑✒✏ ✤✒❩ ✱❸❭✒✤✒✜✒✖✕✘✒✔P✱➹❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛❊❡ ➏✗✓✒❲✕❜✒❛✕❱✗✃✫✵ ➢ ➝✗✵ ✙✕✘✗✖✕✢✗✙✕✔ ✳✒❷✫✪ ✙✕✘✗✖✕✢✗✙✕✔ ❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛❫✪ ✷
slide-28
SLIDE 28 – 28 – 15-213, F’02 Echo Server: Main Loop Echo Server: Main Loop The server loops endlessly, waiting for connection The server loops endlessly, waiting for connection requests, then reading input from the client, and requests, then reading input from the client, and echoing the input back to the client. echoing the input back to the client. ❨✗✚✴✤✕✔P✱➇✵ ✧ ✏✒✑ ✣✒✙✕✘❑✚✗✖✕✘ ✚✒✔✒✛ ✣✕✭✒✔✗❩✒✤✕★✒✢✗✙✕✘ ✖✕❳✒✘ ❭✒✤✒✜❝✖✕✘✒✔✗✤✕✔✒★ ✜✕✭✗✣✕✮✒✘✗✖ ✑✒✏ ✬✴❳✗✤✒❭✕✘P✱❸❷✗✵ ✧ ✏✒✑ ❴✫✣✒✣✕✘✕❪✫✖❊✱➇✵✫➆ ✬✗✚✗✤✒✖ ❩✕✭✗✙ ✚ ✣✕✭✒✔✒✔❝✘✗✣✒✖✒✤✕✭✒✔ ✙✕✘✒➮✒✢✒✘✗✜✒✖ ✑✒✏ ✏✒✑ ✘✗✣✕❳✒✭P✱➇✵✫➆ ✙✕✘✒✚✒✛ ✚✒✔✒✛ ✘✗✣✕❳✒✭ ✤✕✔✕❪❞✢✗✖ ❭✒✤✕✔✒✘✗✜ ❩✒✙✕✭✕❨ ✣✒❭✒✤✕✘✒✔✗✖ ✖✒✤✒❭ ❛✒➓✒❵ ✑✒✏ ✏✒✑ ➛ ❭✕✭✗✜✕✘P✱➇✵✫➆ ✣✒❭✕✭✗✜✕✘ ✖✕❳✒✘ ✣✕✭✒✔✒✔✒✘✗✣❝✖✒✤✕✭✒✔ ✑✒✏ ✷ ✷
slide-29
SLIDE 29 – 29 – 15-213, F’02 blocks waiting for a connection request. blocks waiting for a connection request. returns a returns a connected descriptor connected descriptor ( ( ) with ) with the same properties as the the same properties as the listening descriptor listening descriptor ( (
  • Returns when the connection between client and server is
created and ready for I/O transfers.
  • All I/O with the client will be done via the connected socket.
also fills in client’s IP address. also fills in client’s IP address. Echo Server: Echo Server: ✤✕✔✗✖ ❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛❮✪ ✏✒✑ ❭✒✤✒✜✒✖✕✘✒✔✗✤✕✔✒★ ✛✒✘✗✜✒✣✒✙✒✤✩❪✫✖✕✭✗✙ ✑✒✏ ✤✕✔✗✖ ✣✕✭✒✔✒✔✗❩✕✛❈✪ ✏✒✑ ✣✕✭✒✔✒✔✒✘✗✣✒✖✕✘✒✛ ✛✒✘✗✜✒✣✒✙✒✤✩❪✫✖✕✭✗✙ ✑✒✏ ✜❑✖✒✙✕✢✗✣✒✖ ✜✕✭✗✣✕✮✒✚✒✛✒✛✗✙✍✥✫✤✕✔ ✣✒❭✒✤✕✘✒✔✗✖✕✚✒✛✒✛✗✙✶✪ ✤✦✔✗✖ ✣✒❭✒✤✕✘✒✔✗✖✒❭✕✘✒✔❮✪ ✣✒❭✒✤✕✘✒✔✗✖✒❭✕✘✒✔ ➑ ✜✒✤✒❾✕✘✒✭✗❩❊✱❸✣✒❭✒✤✕✘✒✔✗✖✕✚✒✛✒✛✗✙❢✵✴✪ ✣✕✭✒✔✒✔✗❩✕✛ ➑ ❴✫✣✒✣✕✘✕❪✫✖❊✱➈❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛➀❡ ✱❸❲✩❴ ✑✗✵✒➣➊✣✒❭✒✤✕✘✒✔✗✖✕✚✒✛✒✛✗✙➉❡ ➣✦✣✒❭✒✤✕✘✒✔✗✖✒❭✕✘✒✔✶✵✗✪
slide-30
SLIDE 30 – 30 – 15-213, F’02 Echo Server: Illustrated Echo Server: Illustrated ❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛➅✱❸❰✴✵ Client
  • 1. Server blocks in
Ï✺Ð✼Ð☛Ñ✝ÒÔÓ , waiting for connection request on listening descriptor Õ✼Ö✺×✺Ó✝Ñ☛Ø✺Ù✼Ú . ✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛ Server ❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛➅✱❸❰✴✵ Client ✣✒❭✒✤✕✘✒✔✗✖✒❩✕✛ Server
  • 2. Client makes connection
request by calling and blocking in Ð☛Û☛Ø✼Ø✺Ñ✺Ð✺ÓÝÜ Connection request ❭✒✤✒✜✒✖✕✘✒✔✗❩✕✛➅✱❸❰✴✵ Client ✣✒❭✒✤✕✘✒✔✴✖✒❩✕✛ Server
  • 3. Server returns
Ð☛Û☛Ø✼Ø✺Ù✼Ú from Ï✺Ð✼Ð☛Ñ✝ÒÔÓ . Client returns from Ð☛Û☛Ø✼Ø✺Ñ✺Ð✺Ó . Connection is now established between Ð☛Õ✼Ö✼Ñ☛ØÞÓ✝Ù✼Ú and Ð☛Û☛Ø✼Ø✺Ù➁Ú . ✣✕✭✒✔✒✔✗❩✕✛➅✱➩❹✗✵
slide-31
SLIDE 31 – 31 – 15-213, F’02 Connected vs. Listening Descriptors Connected vs. Listening Descriptors Listening descriptor Listening descriptor
  • End point for client connection requests.
  • Created once and exists for lifetime of the server.
Connected descriptor Connected descriptor
  • End point of the connection between client and server.
  • A new descriptor is created each time the server accepts a
connection request from a client.
  • Exists only as long as it takes to service client.
Why the distinction? Why the distinction?
  • Allows for concurrent servers that can communicate over
many client connections simultaneously. E.g., Each time we receive a new request, we fork a child to handle the request.
slide-32
SLIDE 32 – 32 – 15-213, F’02 Echo Server: Identifying the Client Echo Server: Identifying the Client The server can determine the domain name and IP The server can determine the domain name and IP address of the client. address of the client. ✜❑✖✒✙✕✢✗✣✒✖ ❳✒✭✗✜✒✖✕✘✒✔✗✖ ✑✕❳✕❪❊✪ ✏✒✑ ❪✗✭✗✤✕✔✗✖✕✘✗✙ ✖✕✭ ❯✕❱✫❲ ❳✒✭✗✜✒✖ ✘✒✔✗✖✒✙✕✰ ✑✒✏ ✣✕❳✒✚✗✙ ✑➊❳✒✚✒✛✒✛✗✙✩❪➦✪ ✏✒✑ ❪✗✭✗✤✕✔✗✖✕✘✗✙ ✖✕✭ ✛✒✭✗✖✒✖✕✘✒✛ ✛✒✘✗✣✒✤✩❨✗✚✗❭ ✜✒✖✒✙✒✤✕✔✒★ ✑✒✏ ❳✕❪ ➑ ➘✒✘✗✖✕❳✒✭✗✜✒✖✩✯✗✰✒✚✒✛✒✛✗✙➦✱✒✱❸✣✕✭✒✔✗✜✒✖ ✣✕❳✒✚✗✙ ✑✗✵✒➣➶✣✒❭✒✤✕✘✒✔✗✖✕✚✒✛✒✛✗✙➉❻➇✜❑✤✕✔✕✥❢✚✒✛✒✛✗✙❈❻➇✜✩✥✗✚✒✛✒✛✗✙❫❡ ✜✒✤✒❾✕✘✒✭✗❩❊✱❸✣✒❭✒✤✕✘❑✔✗✖✕✚✒✛✒✛✗✙➉❻➇✜✒✤✕✔✕✥❢✚✒✛❑✛✗✙❈❻➇✜✩✥❢✚✒✛✒✛✗✙✗✵✫❡ ❴✗❵✕✥✫✓✩❱✗❛✒❜✫✵✗✪ ❳✒✚✒✛✒✛✗✙✩❪ ➑ ✤✕✔✒✘✗✖❣✥✗✔✗✖✕✭✒✚P✱❸✣✒❭✒✤✕✘✒✔✗✖✕✚✒✛✒✛✗✙➉❻➇✜✒✤✦✔✕✥❢✚✒✛✒✛✗✙✗✵✗✪ ❪✫✙✒✤✕✔✗✖✒❩➀✱➇➃✕✜✕✘✗✙✕➋✒✘✗✙ ✣✕✭✒✔✒✔✒✘✗✣✒✖✕✘✒✛ ✖✕✭ ➴✒✜ ✱❸➴✒✜✗✵✕➷✕✔✫➃✫❡ ❳✕❪✫✳✦➧✒❳✕✥✗✔✒✚✕❨✗✘❊❡ ❳✒✚✒✛✒✛✗✙✩❪❈✵✗✪
slide-33
SLIDE 33 – 33 – 15-213, F’02 Echo Server: Echo Server: ➋✒✭✗✤✦✛ ✘✗✣✕❳✒✭P✱➟✤✕✔✗✖ ✣✕✭✒✔✒✔✗❩✕✛❞✵ ✧ ✜✒✤✒❾✕✘✕✥✫✖ ✔❈✪ ✣✕❳✒✚✗✙ ✯✗✢✗❩❊❶✲➍✒❴✗➎✒➏✗✓✩❱✗❛✫❺✗✪ ✙✒✤✕✭➊✥✫✖ ✙✒✤✕✭❈✪ ➔ ✤✕✭✕✥✶✙✕✘✒✚✒✛✗✤✕✔✗✤✒✖✩✯ß✱➇➣✕✙✒✤✕✭❊❡ ✣✕✭✒✔✒✔✗❩✕✛⑧✵✗✪ ✬✴❳✗✤✒❭✕✘P✱✒✱❼✔ ➑ ➔ ✤✕✭✕✥à✙✕✘✒✚✒✛✗❭✒✤✕✔✒✘✕✯→✱➇➣✕✙✒✤✦✭❊❡ ✯✗✢✗❩❈❡ ➍✒❴✗➎✒➏✗✓✩❱✗❛✫✵✒✵ ↕❸➑ ➝✗✵ ✧ ❪✫✙✒✤✕✔✗✖✒❩❊✱➇➃✕✜✕✘✗✙✕➋✒✘✗✙ ✙✕✘✗✣✕✘✗✤✕➋✒✘✒✛ ➴✕✛ ✯✗✰✗✖✕✘✗✜✒➷✕✔✫➃✫❡ ✔⑧✵✗✪ ➔ ✤✕✭✕✥➬✬✫✙✒✤✒✖✕✘✒✔➪✱❸✣✕✭✒✔✒✔✗❩✕✛➀❡ ✯✗✢✗❩❈❡ ✔✫✵✗✪ ✷ ✷ The server uses RIO to read and echo text lines until The server uses RIO to read and echo text lines until EOF (end-of-file) is encountered. EOF (end-of-file) is encountered.
  • EOF notification caused by client calling
② ❥❈●á■✫❇ ❐ ② ❥❈③❈❇✫▼P❉ ❤ ❘P❒P④
  • IMPORTANT: EOF is a condition, not a particular data byte.
slide-34
SLIDE 34 – 34 – 15-213, F’02 Testing Servers Using Testing Servers Using The The program is invaluable for testing servers program is invaluable for testing servers that transmit ASCII strings over Internet connections that transmit ASCII strings over Internet connections
  • Our simple echo server
  • Web servers
  • Mail servers
Usage: Usage:
  • â❈▼❊③✫ã❍ä
  • Creates a connection with a server running on
and listening on port
slide-35
SLIDE 35 – 35 – 15-213, F’02 Testing the Echo Server With Testing the Echo Server With ✯✗✚✴✜✒✜✕➧ å✒æ✕ç✗è✒é✒å✒ê✒ë✒å✒ê ì✗í✒í✒í ✜✕✘✗✙✕➋✒✘✗✙ ✘✗✜❑✖✕✚✕✯✫❭✒✤✒✜✕❳✒✘✒✛ ✣✕✭✒✔✒✔✒✘✗✣✒✖✒✤✕✭✒✔ ✬✫✤✒✖✕❳ ➡ ✓✕❜✒❜✒➱✒î✕❴✒ï ➡ ❻ ➛ ➍ ➛ ➏ ✱❸❷✒➒✒❿❈❻➇➒❈❻➇❷✗ð✕❹❈❻➇➒✒❹✒➒✗✵ ✜✕✘✗✙✕➋✒✘✗✙ ✙✦✘✗✣✕✘✗✤✕➋✒✘✒✛ ñ ✯✗✰✗✖✕✘✗✜❈➆ ❷✒➒✒❰ ✜✕✘✗✙✕➋✒✘✗✙ ✘✗✜❑✖✕✚✕✯✫❭✒✤✒✜✕❳✒✘✒✛ ✣✕✭✒✔✒✔✒✘✗✣✒✖✒✤✕✭✒✔ ✬✫✤✒✖✕❳ ➡ ✓✕❜✒❜✒➱✒î✕❴✒ï ➡ ❻ ➛ ➍ ➛ ➏ ✱❸❷✒➒✒❿❈❻➇➒❈❻➇❷✗ð✕❹❈❻➇➒✒❹✒➒✗✵ ✜✕✘✗✙✕➋✒✘✗✙ ✙✦✘✗✣✕✘✗✤✕➋✒✘✒✛ ❿ ✯✗✰✗✖✕✘✗✜❈➆ ❹✒ñ✗ò✕ó✒❿✗ð ✮✗✤✒✖❑✖✕✰✒❳✒✚✕✬✗✮➬➧ ô✕å✒õ✕ö✗å✗ô ÷✫ø✒é✒é ì✗í✒í✒í ❜✗✙✕✰✗✤✕✔✒★ ❷✒➒✒❿❈❻➇➒❈❻➇➒✒➒✒➒❈❻➇❿✒ñ❈❻✒❻✒❻ ➛ ✭✒✔✒✔✒✘✗✣✒✖✕✘✒✛ ✖✕✭ ù✕❴✫❲✒❲❈❻ ➛ ➍ ➛ ➏❊❻ ➛ ❲❈❻ ➛ ➍✗➙❊❻❸❛✒❯✒➙❊❻ ❛✗✜✒✣✕✚✕❪✗✘ ✣✕❳✒✚✗✙✕✚✗✣✒✖✕✘✗✙ ✤✒✜ ➤➇ú✗❺✫➤✒❻ ❷❑➒✒❰ ❷❑➒✒❰ ➛ ✭✒✔✒✔✒✘✗✣✒✖✒✤✕✭❑✔ ✣✒❭✕✭✗✜✕✘✒✛ ✯✗✰ ❩✕✭✗✙✕✘✗✤✕★✒✔ ❳✒✭✗✜✒✖❈❻ ✮✗✤✒✖❑✖✕✰✒❳✒✚✕✬✗✮➬➧ ô✕å✒õ✕ö✗å✗ô ÷✫ø✒é✒é ì✗í✒í✒í ❜✗✙✕✰✗✤✕✔✒★ ❷✒➒✒❿❈❻➇➒❈❻➇➒✒➒✒➒❈❻➇❿✒ñ❈❻✒❻✒❻ ➛ ✭✒✔✒✔✒✘✗✣✒✖✕✘✒✛ ✖✕✭ ù✕❴✫❲✒❲❈❻ ➛ ➍ ➛ ➏❊❻ ➛ ❲❈❻ ➛ ➍✗➙❊❻❸❛✒❯✒➙❊❻ ❛✗✜✒✣✕✚✕❪✗✘ ✣✕❳✒✚✗✙✕✚✗✣✒✖✕✘✗✙ ✤✒✜ ➤➇ú✗❺✫➤✒❻ ❹✒ñ✴ò✕ó✒❿✗ð ❹✒ñ✴ò✕ó✒❿✗ð ➛ ✭✒✔✒✔✒✘✗✣✒✖✒✤✕✭❑✔ ✣✒❭✕✭✗✜✕✘✒✛ ✯✗✰ ❩✕✭✗✙✕✘✗✤✕★✒✔ ❳✒✭✗✜✒✖❈❻ ✮✗✤✒✖❑✖✕✰✒❳✒✚✕✬✗✮➬➧
slide-36
SLIDE 36 – 36 – 15-213, F’02 Running the Echo Client and Server Running the Echo Client and Server ✯✗✚✴✜✒✜✕➧ å✒æ✕ç✗è✒é✒å✒ê✒ë✒å✒ê ì✗í✒í✒í ✜✕✘✗✙✕➋✒✘✗✙ ✘✗✜❑✖✕✚✕✯✫❭✒✤✒✜✕❳✒✘✒✛ ✣✕✭✒✔✒✔✒✘✗✣✒✖✒✤✕✭✒✔ ✬✫✤✒✖✕❳ ➡ ✓✕❜✒❜✒➱✒î✕❴✒ï ➡ ❻ ➛ ➍ ➛ ➏ ✱❸❷✒➒✒❿❈❻➇➒❈❻➇❷✗ð✕❹❈❻➇➒✒❹✒➒✗✵ ✜✕✘✗✙✕➋✒✘✗✙ ✙✦✘✗✣✕✘✗✤✕➋✒✘✒✛ ❹ ✯✗✰✗✖✕✘✗✜❈➆ ❷✒➒✒❰ ✜✕✘✗✙✕➋✒✘✗✙ ✘✗✜❑✖✕✚✕✯✫❭✒✤✒✜✕❳✒✘✒✛ ✣✕✭✒✔✒✔✒✘✗✣✒✖✒✤✕✭✒✔ ✬✫✤✒✖✕❳ ➡ ✓✕❜✒❜✒➱✒î✕❴✒ï ➡ ❻ ➛ ➍ ➛ ➏ ✱❸❷✒➒✒❿❈❻➇➒❈❻➇❷✗ð✕❹❈❻➇➒✒❹✒➒✗✵ ✜✕✘✗✙✕➋✒✘✗✙ ✙✦✘✗✣✕✘✗✤✕➋✒✘✒✛ ó ✯✗✰✗✖✕✘✗✜❈➆ ❹✒ñ✗ò✕ó✒❿✗ð ❻❑❻✒❻ ✮✗✤✒✖❑✖✕✰✒❳✒✚✕✬✗✮➬➧ å✒æ✕ç✗è✒æ✒õ✒û✒å✕ö✫ô ÷✫ø✒é✒é ì✗í✒í✒í ❽✒❭✕✘✒✚✴✜✕✘ ✘✒✔✗✖✕✘✗✙ ❨✫✜✕★➦➆ ❷✒➒✒❰ ❛✗✣✕❳✒✭ ❩❑✙✕✭✕❨ ✜✕✘✗✙✕➋✒✘✗✙❈➆ ❷✒➒✒❰ ✮✗✤✒✖❑✖✕✰✒❳✒✚✕✬✗✮➬➧ å✒æ✕ç✗è✒æ✒õ✒û✒å✕ö✫ô ÷✫ø✒é✒é ì✗í✒í✒í ❽✒❭✕✘✒✚✴✜✕✘ ✘✒✔✗✖✕✘✗✙ ❨✫✜✕★➦➆ ❹✒ñ✗ò✕ó✒❿✗ð ❛✗✣✕❳✒✭ ❩❑✙✕✭✕❨ ✜✕✘✗✙✕➋✒✘✗✙❈➆ ❹✒ñ✗ò✕ó✒❿✗ð ✮✗✤✒✖❑✖✕✰✒❳✒✚✕✬✗✮➬➧
slide-37
SLIDE 37 – 37 – 15-213, F’02 For More Information For More Information
  • W. Richard Stevens, “Unix Network Programming:
  • W. Richard Stevens, “Unix Network Programming:
Networking APIs: Sockets and XTI”, Volume 1, Networking APIs: Sockets and XTI”, Volume 1, Second Edition, Prentice Hall, 1998. Second Edition, Prentice Hall, 1998.
  • THE network programming bible.
Complete versions of the echo client and server are Complete versions of the echo client and server are developed in the text. developed in the text.
  • Available from
② ■✫◆✫✐❈✐ ④ ② ■⑤④ ② ❖❊â ④✕❇❈❘✫â
  • You should compile and run them for yourselves to see how
they work.
  • Feel free to borrow any of this code.