BSD UNIX transport API: The Socket Interface most networking - - PDF document

bsd unix transport api the socket interface
SMART_READER_LITE
LIVE PREVIEW

BSD UNIX transport API: The Socket Interface most networking - - PDF document


slide-1
SLIDE 1

1 29 March, 2002 The Computer Communications Course

BSD UNIX transport API: The Socket Interface

2 29 March, 2002 The Computer Communications Course

The Client-Server Programming Paradigm

  • most networking applications can be divided into two pieces:

most networking applications can be divided into two pieces: client client and and server server

✁✄✂✆☎ ✝ ✞✠✟☛✡☞✝ ✌✎✍✏✌✏✍✏✑✒☎ ☎ ✓✎✌✕✔✗✖✙✘✚✡☛✛✚☎ ✝ ✜☛✞✒✢✤✣✗✘ ✖✙✥✚✞✙✌☛✌✙✦✕✥✚✖✙✧★✧✩✍✙✟✕✝ ✥☛✑✗✡ ✞✕✌✎✪✫✝ ✡☛✔☞✖✒✟✚✞✬✌☛✞✒✘✚✜✚✞✒✘ ✑✗✡✩✑☞✡✗✝ ✧✫✞✭✦✮✌✙✝ ✧★✣✙☎ ✞✒✘★✢✕✞✙✌✙✝ ✯✒✟ ✁✭✰✆✞✠✘ ✜✚✞✠✘✩✍✏✌✏✍✏✑✒☎ ☎ ✓✬✘✚✍✙✟✚✌✲✱✏✖✙✘ ✞✒✜✚✞✒✘✗✦✕✥✚✖✙✧★✧✩✍✙✟✕✝ ✥☛✑✗✡ ✞✕✌✎✪✫✝ ✡☛✔✳✧✩✍✙☎ ✡✗✝ ✣✒☎ ✞✤✥✕☎ ✝ ✞✠✟☛✡ ✌✲✑✗✡ ✑✙✟✚✓✬✯✒✝ ✜✚✞✄✟✲✧✫✖✙✧✫✞✄✟☛✡✗✦✗✢✙✞✕✌✙✝ ✯✙✟☞✝ ✌✎✥☛✖✙✧★✣✙☎ ✞✙✴ ✰✆✞✒✘✚✜✚✞✒✘✵✪✆✑✒✝ ✡ ✌✲✱✏✖✙✘★✘ ✞✙✶✗✍✏✞✕✌✏✡ ✌✲✱✕✘ ✖✙✧✵✥✕☎ ✝ ✞✠✟☛✡✚✌★✑✒✟✏✢☞✌☛✞✠✘✚✜✚✞✕✌✎✡☛✔✗✞✠✧✲✷ ✸✒✹✠✺✏✻★✼ ✻✗✽ ✾ ✻✕✽❀✿ ❁☛❂❃✻✙❄ ❅ ✺✏✻✕✽❆✺☛❁☛❂✚❇✒❈ ✻✎✽ ✻☛❉☛❊ ✻✗✼ ❅ ✼✩❄ ❅ ✻✕✽ ❁✚❅☛❄ ✾ ✻✙❈ ❋✕● ❍ ✽❀✿ ❍ ❂☛✿ ❊☛✽ ✽ ✻✏❂ ❅☛❈ ❋✲■ ❏✚❋★✼ ❑✚❁✚▲✄❂✏❄ ❂ ▼✲✿ ✺✕❄ ❈ ❇✲❑✏✽ ❍ ✿ ✻✗✼ ✼ ✻✏✼❃◆ ✂✆☎ ✝ ✞✠✟☛✡✩✑✏✌✕❖☛✌★✑✎✌☛✞✠✘ ✜✚✞✠✘✩✡ ✖✳✢✕✖✎✌✏✖✙✧✫✞✬✪✆✖✙✘✏❖★✑✒✟✏✢✬✌☛✞✠✟✏✢◗P✗✑✙✥✗❖✲✡☛✔✕✞✤✘ ✞✕✌✏✍✒☎ ✡ ✌✕✷

request response Server Client

3 29 March, 2002 The Computer Communications Course

UNIX I/O Paradigm and Network I/O

  • ❘❃❙✩❚✙❯
❘❃❙✩❚✙❯ ✖✙✣✏✞✠✟✏✛ ✘ ✞✙✑✕✢✒✛ ✪❀✘✗✝ ✡✚✞✒✛ ✥✙☎ ✖✗✌☛✞ ✖✙✣✏✞✠✟✏✛ ✘ ✞✙✑✕✢✒✛ ✪❀✘✗✝ ✡✚✞✒✛ ✥✙☎ ✖✗✌☛✞ ✣✏✑✕✘ ✑✕✢✄✝ ✯✕✧ ✣✏✑✕✘ ✑✕✢✄✝ ✯✕✧
  • ✟✚✞✙✡☛✪✆✖✙✘☛❖☞✥✚✖✙✧★✧✩✍✙✟✕✝
✥☛✑✗✡✗✝ ✖✒✟✩✱✗✍✙✟✏✥☛✡✗✝ ✖✒✟✚✑✒☎ ✝ ✡ ✓✤✝ ✌✎✧✫✖✙✘ ✞✤✥✚✖✙✧★✣✒☎ ✞✒✴✭❱ ✟✚✞✙✡☛✪✆✖✙✘☛❖☞✥✚✖✙✧★✧✩✍✙✟✕✝ ✥☛✑✗✡✗✝ ✖✒✟✩✱✗✍✙✟✏✥☛✡✗✝ ✖✒✟✚✑✒☎ ✝ ✡ ✓✤✝ ✌✎✧✫✖✙✘ ✞✤✥✚✖✙✧★✣✒☎ ✞✒✴✭❱ ❲ ❲ ✌✗✣✏✞✒✥✙✝ ✱✏✓✬✥☛✖✙✧★✧✩✍✕✟✕✝ ✥✚✑✕✡✗✝ ✖✒✟★✞✠✟✏✢✒✣✏✖✠✝ ✟☛✡ ✌ ✌✗✣✏✞✒✥✙✝ ✱✏✓✬✥☛✖✙✧★✧✩✍✕✟✕✝ ✥✚✑✕✡✗✝ ✖✒✟★✞✠✟✏✢✒✣✏✖✠✝ ✟☛✡ ✌ ❲ ❲ ✥✕☎ ✝ ✞✠✟☛✡★✜✚✌✲✌☛✞✒✘✚✜✚✞✒✘✎P✗✞✠✔✗✑✕✜✕✝ ✖✙✘ ✥✕☎ ✝ ✞✠✟☛✡★✜✚✌✲✌☛✞✒✘✚✜✚✞✒✘✎P✗✞✠✔✗✑✕✜✕✝ ✖✙✘ ❲ ❲ ✌✗✣✏✞✒✥✙✝ ✱✏✓☞✡☛✘ ✑✒✟✚✌✗✣☛✖✙✘✚✡✲✣✕✘ ✖✕✡✚✖✙✥✚✖✠☎✕❳ ❨✆✂✄❩★✖✙✘ ❘✩❬ ❩✗❭ ✌✗✣✏✞✒✥✙✝ ✱✏✓☞✡☛✘ ✑✒✟✚✌✗✣☛✖✙✘✚✡✲✣✕✘ ✖✕✡✚✖✙✥✚✖✠☎✕❳ ❨✆✂✄❩★✖✙✘ ❘✩❬ ❩✗❭ ❲ ❲ ✞✙✡☛✥ ✞✙✡☛✥
  • ✰✆✞✙✜✚✞✠✘
✑✠☎✕✟✚✞✒✪❪✖✙✣✏✞✒✘ ✑✗✡✕✝ ✟☛✯✎✌☛✓✗✌✏✡ ✞✒✧✮✥✚✑✠☎ ☎ ✌✲✪❆✞✒✘ ✞☞✑✙✢✒✢✕✞✠✢ ✰✆✞✙✜✚✞✠✘ ✑✠☎✕✟✚✞✒✪❪✖✙✣✏✞✒✘ ✑✗✡✕✝ ✟☛✯✎✌☛✓✗✌✏✡ ✞✒✧✮✥✚✑✠☎ ☎ ✌✲✪❆✞✒✘ ✞☞✑✙✢✒✢✕✞✠✢ ✑✏✌✎✪✆✞✄☎ ☎✏✑✏✌✬✟✚✞✙✪❫☎ ✝ P✒✘ ✑✕✘ ✓✬✘ ✖✕✍✗✡✗✝ ✟✚✞✙✌✕✷ ✑✏✌✎✪✆✞✄☎ ☎✏✑✏✌✬✟✚✞✙✪❫☎ ✝ P✒✘ ✑✕✘ ✓✬✘ ✖✕✍✗✡✗✝ ✟✚✞✙✌✕✷
✞✠✟✚✞✠✘ ✑✒☎✕✧✫✞✒✥✏✔✕✑✙✟✕✝ ✌✗✧✵✣✕✘ ✖✕✜✕✝ ✢✙✞✒✢✳✡ ✖✎✑✙✥✏✥☛✖✙✧★✧❃✖✙✢✙✑✗✡ ✞✤✧✫✑✙✟✚✓ ❴ ✞✠✟✚✞✠✘ ✑✒☎✕✧✫✞✒✥✏✔✕✑✙✟✕✝ ✌✗✧✵✣✕✘ ✖✕✜✕✝ ✢✙✞✒✢✳✡ ✖✎✑✙✥✏✥☛✖✙✧★✧❃✖✙✢✙✑✗✡ ✞✤✧✫✑✙✟✚✓ ✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎ ✌★✑✒✟✏✢☞✑✙✢✒✢✒✘ ✞✕✌☛✌✒✝ ✟☛✯✎✌✗✥✏✔✕✞✒✧✫✞✙✌✕✷ ✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎ ✌★✑✒✟✏✢☞✑✙✢✒✢✒✘ ✞✕✌☛✌✒✝ ✟☛✯✎✌✗✥✏✔✕✞✒✧✫✞✙✌✕✷

4 29 March, 2002 The Computer Communications Course

Specifying A Protocol Interface

❬ ✞✕✌✙✝ ✯✙✟✚✞✠✘ ✌✲✑✗✡☞❵✙✞✒✘✏❖✚✞✭☎ ✞✕✓☞✪✆✑✒✟☛✡ ✞✒✢✳✡ ✖☞✑✕✥✗✥✚✖✙✧★✧✫✖✙✢✕✑✕✡ ✞✳✧✩✍✒☎ ✡✗✝ ✣✒☎ ✞✬✌☛✞✙✡✩✖✗✱ ❬ ✞✕✌✙✝ ✯✙✟✚✞✠✘ ✌✲✑✗✡☞❵✙✞✒✘✏❖✚✞✭☎ ✞✕✓☞✪✆✑✒✟☛✡ ✞✒✢✳✡ ✖☞✑✕✥✗✥✚✖✙✧★✧✫✖✙✢✕✑✕✡ ✞✳✧✩✍✒☎ ✡✗✝ ✣✒☎ ✞✬✌☛✞✙✡✩✖✗✱ ✥✚✖✙✧★✧✩✍✙✟✕✝ ✥✚✑✗✡✗✝ ✖✒✟✎✣✗✘ ✖✕✡ ✖✙✥☛✖✠☎ ✌✕✷ ✥✚✖✙✧★✧✩✍✙✟✕✝ ✥✚✑✗✡✗✝ ✖✒✟✎✣✗✘ ✖✕✡ ✖✙✥☛✖✠☎ ✌✕✷ ❨❆✔✕✞✕✓✬✣✕✘ ✖✕✜✕✝ ✢✙✞✒✢✳✯✏✞✠✟✚✞✠✘ ✑✠☎ ✝ ✡ ✓✎✱✏✑✕✘✎P✗✞✕✓✗✖✒✟✏✢✤❨✆✂✄❩✏❛ ❚ ❩✙❱ ❨❆✔✕✞✕✓✬✣✕✘ ✖✕✜✕✝ ✢✙✞✒✢✳✯✏✞✠✟✚✞✠✘ ✑✠☎ ✝ ✡ ✓✎✱✏✑✕✘✎P✗✞✕✓✗✖✒✟✏✢✤❨✆✂✄❩✏❛ ❚ ❩✙❱ ❲ ❲ ✧✩✍✒☎ ✡✗✝ ✣✒☎ ✞ ✧✩✍✒☎ ✡✗✝ ✣✒☎ ✞ ❜✠❝☛❞✆❡ ❞✙❢✚❞✙❣✄❤ ✐✏❥✎❦ ❣ ❦ ❧✗♠ ❜✠❝☛❞✆❡ ❞✙❢✚❞✙❣✄❤ ✐✏❥✎❦ ❣ ❦ ❧✗♠ ❲ ❲ ✧✩✍✒☎ ✡✗✝ ✣✒☎ ✞ ✧✩✍✒☎ ✡✗✝ ✣✒☎ ✞ ❡ ♥✏❜✠❧✏♠☞❞✠❤❆♠✗❧✙❝✠♦ ❦ ❢✚❧ ❡ ♥✏❜✠❧✏♠☞❞✠❤❆♠✗❧✙❝✠♦ ❦ ❢✚❧ ❲ ❲ ✧✩✍✒☎ ✡✗✝ ✣✒☎ ✞ ✧✩✍✒☎ ✡✗✝ ✣✒☎ ✞ ✐✕♣✠♣✕❝☛❧✏♠☛♠✙❦ q rs❤ ✐✏❥✎❦ ❣ ❦ ❧✗♠ ✐✕♣✠♣✕❝☛❧✏♠☛♠✙❦ q rs❤ ✐✏❥✎❦ ❣ ❦ ❧✗♠

5 29 March, 2002 The Computer Communications Course

The Socket Abstraction

  • ❨❆✔✕✞☞✌✏✖✙✥✗❖☛✞✙✡☞✝
✌✲✑✳✟✚✞✙✪❪✑✒P✗✌✗✡☛✘ ✑✕✥☛✡✗✝ ✖✒✟✩✱✗✖✙✘✲✟✚✞✙✡✚✪✆✖✙✘✏❖✎✥☛✖✙✧★✧✩✍✕✟✕✝ ✥✚✑✕✡✗✝ ✖✒✟✗✷ ❨❆✔✕✞☞✌✏✖✙✥✗❖☛✞✙✡☞✝ ✌✲✑✳✟✚✞✙✪❪✑✒P✗✌✗✡☛✘ ✑✕✥☛✡✗✝ ✖✒✟✩✱✗✖✙✘✲✟✚✞✙✡✚✪✆✖✙✘✏❖✎✥☛✖✙✧★✧✩✍✕✟✕✝ ✥✚✑✕✡✗✝ ✖✒✟✗✷
  • t
✝ ❖☛✞✬✱✒✝ ☎ ✞✙✌✙✦✏✞✕✑✕✥✗✔☞✌☛✖✙✥✗❖☛✞✙✡☞✝ ✌✳✝ ✢✙✞✠✟☛✡✗✝ ✱✒✝ ✞✠✢✤P✕✓✎✑✎✌✗✧✫✑✒☎ ☎✙✝ ✟☛✡ ✞✙✯✗✞✒✘★✥✚✑✠☎ ☎ ✞✠✢ t ✝ ❖☛✞✬✱✒✝ ☎ ✞✙✌✙✦✏✞✕✑✕✥✗✔☞✌☛✖✙✥✗❖☛✞✙✡☞✝ ✌✳✝ ✢✙✞✠✟☛✡✗✝ ✱✒✝ ✞✠✢✤P✕✓✎✑✎✌✗✧✫✑✒☎ ☎✙✝ ✟☛✡ ✞✙✯✗✞✒✘★✥✚✑✠☎ ☎ ✞✠✢ ✝ ✡ ✌ ✝ ✡ ✌ ♠✕❞✙❢☛✉✗❧❆❡❆♣✕❧✏♠✙❢☛❝✗❦ ❜✫❡ ❞✗❝ ♠✕❞✙❢☛✉✗❧❆❡❆♣✕❧✏♠✙❢☛❝✗❦ ❜✫❡ ❞✗❝ ✷ ✷ ❘❃❙✩❚✙❯ ✑✠☎ ☎ ✖✙✥✚✑✕✡ ✞✕✌✲✌☛✖✙✥✗❖☛✞✙✡✲✢✕✞✙✌✗✥✏✘✗✝ ✣✗✡ ✖✙✘ ✌✳✝ ✟✲✡☛✔✗✞✬✌☛✑✙✧✫✞✬✡✚✑✙P✄☎ ✞☞✑✗✌★✱✠✝ ☎ ✞ ❘❃❙✩❚✙❯ ✑✠☎ ☎ ✖✙✥✚✑✕✡ ✞✕✌✲✌☛✖✙✥✗❖☛✞✙✡✲✢✕✞✙✌✗✥✏✘✗✝ ✣✗✡ ✖✙✘ ✌✳✝ ✟✲✡☛✔✗✞✬✌☛✑✙✧✫✞✬✡✚✑✙P✄☎ ✞☞✑✗✌★✱✠✝ ☎ ✞ ✢✕✞✙✌✗✥✏✘✗✝ ✣✗✡ ✖✙✘ ✌✕✷ ✢✕✞✙✌✗✥✏✘✗✝ ✣✗✡ ✖✙✘ ✌✕✷
  • ✰✫✝
✟☛✯✠☎ ✞✬✌☛✓✏✌✗✡ ✞✒✧✵✥☛✑✒☎ ☎✒✝ ✌✲✌✏✍✏✱✏✱✒✝ ✥✙✝ ✞✄✟☛✡✩✡ ✖✳✥✏✘ ✞✕✑✕✡ ✞✬✑✙✟✚✓✎✌✏✖✙✥✗❖☛✞✙✡✏✷ ✰✫✝ ✟☛✯✠☎ ✞✬✌☛✓✏✌✗✡ ✞✒✧✵✥☛✑✒☎ ☎✒✝ ✌✲✌✏✍✏✱✏✱✒✝ ✥✙✝ ✞✄✟☛✡✩✡ ✖✳✥✏✘ ✞✕✑✕✡ ✞✬✑✙✟✚✓✎✌✏✖✙✥✗❖☛✞✙✡✏✷
✟✏✥☛✞✬✡✏✔✗✞✬✌☛✖✙✥✕❖✚✞✒✡★✔✕✑✏✌✬P✗✞✙✞✠✟✲✥✗✘ ✞✕✑✗✡✚✞✒✢✄✦✏✑✙✟★✑✕✣✕✣✙☎ ✝ ✥✚✑✕✡✗✝ ✖✠✟ ✈ ✟✏✥☛✞✬✡✏✔✗✞✬✌☛✖✙✥✕❖✚✞✒✡★✔✕✑✏✌✬P✗✞✙✞✠✟✲✥✗✘ ✞✕✑✗✡✚✞✒✢✄✦✏✑✙✟★✑✕✣✕✣✙☎ ✝ ✥✚✑✕✡✗✝ ✖✠✟ ✧✩✍✏✌✏✡✲✧✫✑✙❖☛✞☞✑✙✢✒✢✄✝ ✡✗✝ ✖✒✟☛✑✒☎✏✌☛✓✏✌✏✡✚✞✒✧✵✥☛✑✒☎ ☎ ✌✎✡ ✖☞✌✗✣☛✞✠✥✕✝ ✱✏✓☞✡☛✔✕✞✳✢✙✞✙✡ ✑✠✝ ☎ ✌✲✖✗✱ ✧✩✍✏✌✏✡✲✧✫✑✙❖☛✞☞✑✙✢✒✢✄✝ ✡✗✝ ✖✒✟☛✑✒☎✏✌☛✓✏✌✏✡✚✞✒✧✵✥☛✑✒☎ ☎ ✌✎✡ ✖☞✌✗✣☛✞✠✥✕✝ ✱✏✓☞✡☛✔✕✞✳✢✙✞✙✡ ✑✠✝ ☎ ✌✲✖✗✱ ✞✙✴✒✑✕✥☛✡★✍✏✌☛✞✠✷ ✞✙✴✒✑✕✥☛✡★✍✏✌☛✞✠✷

6 29 March, 2002 The Computer Communications Course

System Data Structures for Sockets

family: PF_INET

service: SOCK_STREAM

Local IP: Remote IP: Local port: Remote port: 0: 1: 2: 3: 4:

To the system file table

slide-2
SLIDE 2

7 29 March, 2002 The Computer Communications Course

Creating a Socket

❨❆✔✕✞ ❨❆✔✕✞ ✂✁✂✄✆☎✞✝✠✟ ✂✁✂✄✆☎✞✝✠✟ ✌☛✓✗✌✏✡ ✞✒✧✮✥✚✑✒☎ ☎✗✥✗✘ ✞✙✑✗✡ ✞✙✌★✌☛✖✙✥✕❖✚✞✒✡ ✌★✖✠✟✲✢✕✞✠✧✫✑✙✟✏✢ ❱ ✌☛✓✗✌✏✡ ✞✒✧✮✥✚✑✒☎ ☎✗✥✗✘ ✞✙✑✗✡ ✞✙✌★✌☛✖✙✥✕❖✚✞✒✡ ✌★✖✠✟✲✢✕✞✠✧✫✑✙✟✏✢ ❱ ✌✕✢☛✡ ✌✕✢☛✡ ☞✆✌✂✍✏✎✒✑✞✓ ☞✆✌✂✍✏✎✒✑✞✓ ❳❆✣✗✘ ✖✕✡ ✖✙✥☛✖✠☎ ✔✭✱✏✑✙✧✎✝ ☎ ✓✠✦✲✌☛✞✒✘✚✜✕✝ ✥✚✞✏✔✆✡ ✓✙✣☛✞✭✦ ✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎✕❭ ✕ ❳❆✣✗✘ ✖✕✡ ✖✙✥☛✖✠☎ ✔✭✱✏✑✙✧✎✝ ☎ ✓✠✦✲✌☛✞✒✘✚✜✕✝ ✥✚✞✏✔✆✡ ✓✙✣☛✞✭✦ ✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎✕❭ ✕ ❨✆✂✄❩✏❛ ❚ ❩✬✝ ✟☛✡ ✞✒✘✏✟✚✞✙✡✲✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎✏✱✏✑✕✧✎✝ ☎ ✓✠❱ ❨✆✂✄❩✏❛ ❚ ❩✬✝ ✟☛✡ ✞✒✘✏✟✚✞✙✡✲✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎✏✱✏✑✕✧✎✝ ☎ ✓✠❱ ❩✏✖✂✔ ❚✒❙✘✗ ❨ ❩✏✖✂✔ ❚✒❙✘✗ ❨ ✗ ✴✙✑✙✧★✣✙☎ ✞✳✰✆✞✒✘✚✜✕✝ ✥✚✞✤❨✭✓✙✣✏✞✕✌✙❱ ✗ ✴✙✑✙✧★✣✙☎ ✞✳✰✆✞✒✘✚✜✕✝ ✥✚✞✤❨✭✓✙✣✏✞✕✌✙❱ ❲ ❲ ✘ ✞✄☎ ✝ ✑✙P✄☎ ✞✬✌✏✡☛✘ ✞✕✑✕✧✮✢✕✞✄☎ ✝ ✜✚✞✠✘ ✓☞✌☛✞✒✘✚✜✕✝ ✥☛✞ ❳ ✘ ✞✄☎ ✝ ✑✙P✄☎ ✞✬✌✏✡☛✘ ✞✕✑✕✧✮✢✕✞✄☎ ✝ ✜✚✞✠✘ ✓☞✌☛✞✒✘✚✜✕✝ ✥☛✞ ❳ ✰ ✈ ✂✠✙✒✔❀✰❆❨✛✚ ✗✢✜✤✣ ✰ ✈ ✂✠✙✒✔❀✰❆❨✛✚ ✗✢✜✤✣ ❭ ❭ ❲ ❲ ✥✚✖✒✟✗✟☛✞✒✥☛✡✗✝ ✖✒✟✕☎ ✞✕✌✏✌✎✢✕✑✕✡ ✑✗✯✙✘ ✑✕✧✵✢✙✞✄☎ ✝ ✜✚✞✒✘ ✓✎✌☛✞✒✘✚✜✕✝ ✥✚✞ ❳ ✥✚✖✒✟✗✟☛✞✒✥☛✡✗✝ ✖✒✟✕☎ ✞✕✌✏✌✎✢✕✑✕✡ ✑✗✯✙✘ ✑✕✧✵✢✙✞✄☎ ✝ ✜✚✞✒✘ ✓✎✌☛✞✒✘✚✜✕✝ ✥✚✞ ❳ ✰ ✈ ✂✠✙✒✔ ❬✆❴ ✚ ✜✤✣ ✰ ✈ ✂✠✙✒✔ ❬✆❴ ✚ ✜✤✣ ❭ ❭ ❲ ❲ ✘ ✑✗✪s✡ ✓✙✣☛✞ ❳ ✘ ✑✗✪s✡ ✓✙✣☛✞ ❳ ✰ ✈ ✂✠✙✂✔✛✚ ✜✦✥ ✰ ✈ ✂✠✙✂✔✛✚ ✜✦✥ ❭ ❭

8 29 March, 2002 The Computer Communications Course

Socket Inheritance

❘❃❙✩❚✙❯ ✍✏✌☛✞✕✌✎✡☛✔✗✞ ❘❃❙✩❚✙❯ ✍✏✌☛✞✕✌✎✡☛✔✗✞ ✧ ✁✒★✆☎ ✧ ✁✒★✆☎ ✑✒✟✏✢ ✑✒✟✏✢ ✝✏✩✢✝✞✄ ✝✏✩✢✝✞✄ ✌☛✓✗✌✏✡ ✞✒✧✮✥✚✑✒☎ ☎ ✌✲✡✚✖✎✌✏✡ ✑✙✘ ✡✎✟✚✞✙✪ ✑✕✣✕✣✒☎ ✝ ✥☛✑✗✡✗✝ ✖✒✟ ✌☛✓✗✌✏✡ ✞✒✧✮✥✚✑✒☎ ☎ ✌✲✡✚✖✎✌✏✡ ✑✙✘ ✡✎✟✚✞✙✪ ✑✕✣✕✣✒☎ ✝ ✥☛✑✗✡✗✝ ✖✒✟ ✣✕✘ ✖✙✯✕✘ ✑✕✧✫✌✕✷ ❚ ✡☞✝ ✌★✑☞✡✚✪✆✖✙✛ ✌✏✡ ✞✒✣✬✣✗✘ ✖✙✥✚✞✠✢✙✍✕✘ ✞✄❱ ✣✕✘ ✖✙✯✕✘ ✑✕✧✫✌✕✷ ❚ ✡☞✝ ✌★✑☞✡✚✪✆✖✙✛ ✌✏✡ ✞✒✣✬✣✗✘ ✖✙✥✚✞✠✢✙✍✕✘ ✞✄❱ ❲ ❲ ✧ ✁✒★✆☎ ✧ ✁✒★✆☎ ✥✏✘ ✞✙✑✗✡ ✞✕✌✲✑✎✌☛✞✒✣✏✑✕✘ ✑✕✡ ✞✤✥✚✖✙✣✏✓✎✖✗✱✎✡✏✔✗✞✤✥☛✍✕✘☛✘ ✞✠✟☛✡✗☎ ✓✎✞✒✴✙✞✒✥✏✍✗✡✗✝ ✟☛✯ ✥✏✘ ✞✙✑✗✡ ✞✕✌✲✑✎✌☛✞✒✣✏✑✕✘ ✑✕✡ ✞✤✥✚✖✙✣✏✓✎✖✗✱✎✡✏✔✗✞✤✥☛✍✕✘☛✘ ✞✠✟☛✡✗☎ ✓✎✞✒✴✙✞✒✥✏✍✗✡✗✝ ✟☛✯ ✣✕✘ ✖✒✥✚✞✕✌☛✌✕✷ ✣✕✘ ✖✒✥✚✞✕✌☛✌✕✷ ❲ ❲ ❵✙✓✬✥✚✑✒☎ ☎ ✝ ✟☛✯ ❵✙✓✬✥✚✑✒☎ ☎ ✝ ✟☛✯ ✝✏✩✢✝✞✄ ✝✏✩✢✝✞✄ ✦✗✡☛✔✕✞✤✟✚✞✒✪s✥☛✖✙✣☛✓✳✘ ✞✠✣✙☎ ✑✙✥✚✞✙✌✬✝ ✡ ✌☛✞✄☎ ✱☞✪✫✝ ✡☛✔✬✡☛✔✕✞✳✢✙✞✕✌✙✝ ✘ ✞✠✢ ✦✗✡☛✔✕✞✤✟✚✞✒✪s✥☛✖✙✣☛✓✳✘ ✞✠✣✙☎ ✑✙✥✚✞✙✌✬✝ ✡ ✌☛✞✄☎ ✱☞✪✫✝ ✡☛✔✬✡☛✔✕✞✳✢✙✞✕✌✙✝ ✘ ✞✠✢ ✑✕✣✕✣✙☎ ✝ ✥✚✑✕✡✗✝ ✖✒✟ ✣✕✘ ✖✕✯✙✘ ✑✕✧✲✷ ✑✕✣✕✣✙☎ ✝ ✥✚✑✕✡✗✝ ✖✒✟ ✣✕✘ ✖✕✯✙✘ ✑✕✧✲✷ ✥ ✔✕✞✠✟★✑✬✣✗✘ ✖✕✯✙✘ ✑✙✧✵✥☛✑✒☎ ☎ ✌ ✥ ✔✕✞✠✟★✑✬✣✗✘ ✖✕✯✙✘ ✑✙✧✵✥☛✑✒☎ ☎ ✌ ✧ ✁✒★✆☎ ✧ ✁✒★✆☎ ✦✗✡☛✔✕✞◗✟✚✞✙✪✫☎ ✓✬✥✗✘ ✞✕✑✗✡✚✞✒✢✤✣✗✘ ✖✙✥✚✞✙✌☛✌✬✝ ✟✏✔✕✞✒✘✗✝ ✡ ✌ ✦✗✡☛✔✕✞◗✟✚✞✙✪✫☎ ✓✬✥✗✘ ✞✕✑✗✡✚✞✒✢✤✣✗✘ ✖✙✥✚✞✙✌☛✌✬✝ ✟✏✔✕✞✒✘✗✝ ✡ ✌ ✑✕✥✗✥✚✞✙✌☛✌✲✡ ✖☞✑✒☎ ☎✏✖✙✣✏✞✠✟★✌☛✖✙✥✗❖☛✞✙✡ ✌✫✪ ✍✏✌✏✡✫✑✗✌✬✝ ✡✎✝ ✟✏✔✗✞✠✘✗✝ ✡ ✌✲✑✕✥✗✥✚✞✕✌☛✌✎✡ ✖☞✑✒☎ ☎✏✖✙✣☛✞✄✟✩✱✒✝ ☎ ✞✕✌✕✷ ✑✕✥✗✥✚✞✙✌☛✌✲✡ ✖☞✑✒☎ ☎✏✖✙✣✏✞✠✟★✌☛✖✙✥✗❖☛✞✙✡ ✌✫✪ ✍✏✌✏✡✫✑✗✌✬✝ ✡✎✝ ✟✏✔✗✞✠✘✗✝ ✡ ✌✲✑✕✥✗✥✚✞✕✌☛✌✎✡ ✖☞✑✒☎ ☎✏✖✙✣☛✞✄✟✩✱✒✝ ☎ ✞✕✌✕✷ ✥ ✔✕✞✠✟★✑✬✣✗✘ ✖✕✯✙✘ ✑✙✧✵✥☛✑✒☎ ☎ ✌ ✥ ✔✕✞✠✟★✑✬✣✗✘ ✖✕✯✙✘ ✑✙✧✵✥☛✑✒☎ ☎ ✌ ✝✏✩✢✝✏✄ ✝✏✩✢✝✏✄ ✦✏✡✏✔✗✞◗✟✚✞✙✪ ✑✕✣✕✣✒☎ ✝ ✥☛✑✗✡✗✝ ✖✒✟✲✘ ✞✙✡✚✑✒✝ ✟☛✌★✑✕✥✗✥✚✞✙✌☛✌✲✡ ✖ ✦✏✡✏✔✗✞◗✟✚✞✙✪ ✑✕✣✕✣✒☎ ✝ ✥☛✑✗✡✗✝ ✖✒✟✲✘ ✞✙✡✚✑✒✝ ✟☛✌★✑✕✥✗✥✚✞✙✌☛✌✲✡ ✖ ✑✒☎ ☎☛✖✙✣✏✞✠✟★✌☛✖✙✥✗❖☛✞✙✡ ✌✙✷ ✑✒☎ ☎☛✖✙✣✏✞✠✟★✌☛✖✙✥✗❖☛✞✙✡ ✌✙✷

9 29 March, 2002 The Computer Communications Course

Socket Termination

✥ ✔✕✞✠✟★✑✬✣✗✘ ✖✙✥☛✞✕✌☛✌✲✱✒✝ ✟✕✝ ✌✗✔✗✞✙✌✲✍✏✌✙✝ ✟☛✯✎✑✲✌✏✖✙✥✗❖☛✞✙✡☞✝ ✡✲✥✚✑✒☎ ☎ ✌ ✥ ✔✕✞✠✟★✑✬✣✗✘ ✖✙✥☛✞✕✌☛✌✲✱✒✝ ✟✕✝ ✌✗✔✗✞✙✌✲✍✏✌✙✝ ✟☛✯✎✑✲✌✏✖✙✥✗❖☛✞✙✡☞✝ ✡✲✥✚✑✒☎ ☎ ✌ ❢✗❣ ❞☛♠✗❧ ❱ ❱ ✍✏✬ ✌✂☞✒✑ ✍✏✬ ✌✂☞✒✑ ❳ ✌☛✖✙✥✕❖ ✔❀✢✒❭ ✕ ❳ ✌☛✖✙✥✕❖ ✔❀✢✒❭ ✕ ❨❆✔✕✞ ❨❆✔✕✞ ♠✞✭✏✮✆❡ ♣✕❞✰✯✭q ✥✚✑✠☎ ☎✕✥✚✑✗✍✏✌☛✞✙✌★✑✒☎ ☎☛✖✙✘✲✣☛✑✙✘ ✡✩✖✗✱✎✑✲✱✕✍✙☎ ☎ ✛ ✢✙✍✕✣✒☎ ✞✙✴◗✥✚✖✒✟✕✟✚✞✒✥☛✡✗✝ ✖✒✟ ✥✚✑✠☎ ☎✕✥✚✑✗✍✏✌☛✞✙✌★✑✒☎ ☎☛✖✙✘✲✣☛✑✙✘ ✡✩✖✗✱✎✑✲✱✕✍✙☎ ☎ ✛ ✢✙✍✕✣✒☎ ✞✙✴◗✥✚✖✒✟✕✟✚✞✒✥☛✡✗✝ ✖✒✟ ✖✒✟✲✡☛✔✗✞✬✌☛✖✙✥✕❖✚✞✒✡✫✑✗✌☛✌☛✖✙✥✕✝ ✑✗✡ ✞✠✢✬✪✫✝ ✡☛✔☞✌☛✖✙✥✕❖ ✔❀✢✬✡ ✖✤P✕✞☞✌✗✔✙✍✗✡✮✢✕✖✕✪❃✟✗✷ ✖✒✟✲✡☛✔✗✞✬✌☛✖✙✥✕❖✚✞✒✡✫✑✗✌☛✌☛✖✙✥✕✝ ✑✗✡ ✞✠✢✬✪✫✝ ✡☛✔☞✌☛✖✙✥✕❖ ✔❀✢✬✡ ✖✤P✕✞☞✌✗✔✙✍✗✡✮✢✕✖✕✪❃✟✗✷ ❲ ❲ ❚ ✱✬✔✗✖✕✪❫✝ ✌✘✱✆✦✏✱✗✍✕✘✚✡☛✔✗✞✠✘★✘ ✞✒✥✚✞✭✝ ✜✚✞✙✌✲✪✫✝ ☎ ☎✙P✗✞✤✢✄✝ ✌☛✑✒☎ ☎ ✖✕✪✆✞✒✢✠✷ ❚ ✱✬✔✗✖✕✪❫✝ ✌✘✱✆✦✏✱✗✍✕✘✚✡☛✔✗✞✠✘★✘ ✞✒✥✚✞✭✝ ✜✚✞✙✌✲✪✫✝ ☎ ☎✙P✗✞✤✢✄✝ ✌☛✑✒☎ ☎ ✖✕✪✆✞✒✢✠✷ ❲ ❲ ❚ ✱✬✔✗✖✕✪❫✝ ✌☛✲ ✦✏✱✗✍✗✘✚✡☛✔✕✞✒✘✩✌☛✞✠✟✏✢✕✌✎✪✫✝ ☎ ☎✕P✕✞✤✢✄✝ ✌☛✑✠☎ ☎ ✖✕✪✆✞✠✢✠✷ ❚ ✱✬✔✗✖✕✪❫✝ ✌☛✲ ✦✏✱✗✍✗✘✚✡☛✔✕✞✒✘✩✌☛✞✠✟✏✢✕✌✎✪✫✝ ☎ ☎✕P✕✞✤✢✄✝ ✌☛✑✠☎ ☎ ✖✕✪✆✞✠✢✠✷ ❲ ❲ ❚ ✱✬✔✗✖✕✪❫✝ ✌✴✳✄✦✏✱✗✍✕✘✚✡☛✔✗✞✠✘✫✌☛✞✠✟✏✢✙✌★✑✒✟✏✢✳✘ ✞✒✥☛✞✄✝ ✜✚✞✕✌✎✪✫✝ ☎ ☎✙P✕✞✳✢✭✝ ✌☛✑✠☎ ☎ ✖✕✪✆✞✒✢ ❚ ✱✬✔✗✖✕✪❫✝ ✌✴✳✄✦✏✱✗✍✕✘✚✡☛✔✗✞✠✘✫✌☛✞✠✟✏✢✙✌★✑✒✟✏✢✳✘ ✞✒✥☛✞✄✝ ✜✚✞✕✌✎✪✫✝ ☎ ☎✙P✕✞✳✢✭✝ ✌☛✑✠☎ ☎ ✖✕✪✆✞✒✢ ✵ ✵ ☞✏✶✏✷✆✓✹✸✢✌✂✺✼✻ ☞✏✶✏✷✆✓✹✸✢✌✂✺✼✻ ❳ ✌☛✖✙✥✗❖✹✔❆✢✭✦✗✔✕✖✕✪❀❭ ✕ ❳ ✌☛✖✙✥✗❖✹✔❆✢✭✦✗✔✕✖✕✪❀❭ ✕

10 29 March, 2002 The Computer Communications Course

TCP Communication Endpoint

✞✒✪✫☎ ✓✬✥✏✘ ✞✕✑✕✡ ✞✒✢✬✌☛✖✙✥✕❖✚✞✒✡✎✝ ✌☞P✕✖✕✍✙✟✏✢✤✟✚✞✭✝ ✡☛✔✕✞✒✘★✡ ✖✎✌✗✣✏✞✒✥✙✝ ✱✒✝ ✥✎✣✗✘ ✖✕✡ ✖✙✥☛✖✠☎ ❙ ✞✒✪✫☎ ✓✬✥✏✘ ✞✕✑✕✡ ✞✒✢✬✌☛✖✙✥✕❖✚✞✒✡✎✝ ✌☞P✕✖✕✍✙✟✏✢✤✟✚✞✭✝ ✡☛✔✕✞✒✘★✡ ✖✎✌✗✣✏✞✒✥✙✝ ✱✒✝ ✥✎✣✗✘ ✖✕✡ ✖✙✥☛✖✠☎ ✱✏✑✕✧✎✝ ☎ ✓✠✦✕✟✚✖✙✘✵✡ ✖ ✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎✏✌✗✣✏✞✒✥✙✝ ✱✒✝ ✥✩✑✙✢✒✢✒✘ ✞✙✌☛✌✙✝ ✟☛✯✎✌✗✥✗✔✗✞✠✧❃✞✄✷ ✱✏✑✕✧✎✝ ☎ ✓✠✦✕✟✚✖✙✘✵✡ ✖ ✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎✏✌✗✣✏✞✒✥✙✝ ✱✒✝ ✥✩✑✙✢✒✢✒✘ ✞✙✌☛✌✙✝ ✟☛✯✎✌✗✥✗✔✗✞✠✧❃✞✄✷
✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎✏✱✏✑✕✧✎✝ ☎ ✓ ✝ ✌✮✱✕✘ ✞✕✞✳✡ ✖✳✥✏✔✕✖✗✖✗✌☛✞✬✖✒✟✚✞✬✖✙✘★✧✫✖✙✘ ✞☞✑✙✢✒✢✒✘ ✞✕✌✏✌✙✝ ✟☛✯ ✜ ✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎✏✱✏✑✕✧✎✝ ☎ ✓ ✝ ✌✮✱✕✘ ✞✕✞✳✡ ✖✳✥✏✔✕✖✗✖✗✌☛✞✬✖✒✟✚✞✬✖✙✘★✧✫✖✙✘ ✞☞✑✙✢✒✢✒✘ ✞✕✌✏✌✙✝ ✟☛✯ ✌✗✥✗✔✗✞✒✧✫✞✙✌✲✡ ✖✳✢✕✞✙✱✒✝ ✟✚✞✬✑✕✢✠✢✒✘ ✞✕✌☛✌☞✘ ✞✠✣✗✘ ✞✙✌☛✞✠✟☛✡ ✑✕✡✗✝ ✖✒✟✚✌✕✷ ✌✗✥✗✔✗✞✒✧✫✞✙✌✲✡ ✖✳✢✕✞✙✱✒✝ ✟✚✞✬✑✕✢✠✢✒✘ ✞✕✌☛✌☞✘ ✞✠✣✗✘ ✞✙✌☛✞✠✟☛✡ ✑✕✡✗✝ ✖✒✟✚✌✕✷ ❨❆✔✕✞✬✌☛✖✙✥✗❖☛✞✙✡✩✑✙P✕✌✏✡☛✘ ✑✕✥✏✡✗✝ ✖✒✟✎✢✕✞✙✱✒✝ ✟✚✞✕✌✲✑✙✟ ❨❆✔✕✞✬✌☛✖✙✥✗❖☛✞✙✡✩✑✙P✕✌✏✡☛✘ ✑✕✥✏✡✗✝ ✖✒✟✎✢✕✞✙✱✒✝ ✟✚✞✕✌✲✑✙✟ ✐✕♣✠♣✕❝☛❧✏♠☛♠◗❤ ✐✏❥✎❦ ❣ ♥ ✱✏✖✙✘✫✞✙✑✕✥✏✔ ✱✏✖✙✘✫✞✙✑✕✥✏✔ ✡ ✓✙✣✏✞☞✖✗✱ ✑✙✢✒✢✒✘ ✞✕✌✏✌✕✷ ✡ ✓✙✣✏✞☞✖✗✱ ✑✙✢✒✢✒✘ ✞✕✌✏✌✕✷ ❨❆✔✕✞✤❨✆✂✄❩☛❛ ❚ ❩✎✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎ ✌☞❳ ❨❆✔✕✞✤❨✆✂✄❩☛❛ ❚ ❩✎✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎ ✌☞❳ ❩✏✖✂✔ ❚✒❙✘✗ ❨ ❩✏✖✂✔ ❚✒❙✘✗ ❨ ✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎✏✱✏✑✕✧✎✝ ☎ ✓✙❭✄✑✒☎ ☎✏✍✏✌☛✞✬✑ ✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎✏✱✏✑✕✧✎✝ ☎ ✓✙❭✄✑✒☎ ☎✏✍✏✌☛✞✬✑ ✌✙✝ ✟☛✯✒☎ ✞✬✑✕✢✠✢✒✘ ✞✕✌☛✌ ✘ ✞✒✣✕✘ ✞✕✌☛✞✠✟✏✡ ✑✗✡✗✝ ✖✒✟✕❱ ✌✙✝ ✟☛✯✒☎ ✞✬✑✕✢✠✢✒✘ ✞✕✌☛✌ ✘ ✞✒✣✕✘ ✞✕✌☛✞✠✟✏✡ ✑✗✡✗✝ ✖✒✟✕❱ ✜ ✖✂✔ ❚✒❙✘✗ ❨ ✜ ✖✂✔ ❚✒❙✘✗ ❨ ✷ ✷
  • ❨✆✂✄❩✏❛
❚ ❩ ❨✆✂✄❩✏❛ ❚ ❩ ❢☛❞✗❥★❥✽✮✗q✕❦ ❢✚✐✆❡ ❦ ❞✕q✎❧✙q✕♣☛❜✠❞✙❦ q✭❡ ❱ ❱ ❳ ❚ ❩★✑✕✢✒✢✠✘ ✞✙✌☛✌✙✦✕✣☛✖✙✘✚✡✎✟☛✍✕✧★P✕✞✒✘☛❭ ❳ ❚ ❩★✑✕✢✒✢✠✘ ✞✙✌☛✌✙✦✕✣☛✖✙✘✚✡✎✟☛✍✕✧★P✕✞✒✘☛❭ ✈ ✡✏✔✗✞✠✘★✣✗✘ ✖✕✡ ✖✒✥✚✖✠☎ ✌☞✢✕✞✕✱✒✝ ✟✚✞✳✡☛✔✗✞✭✝ ✘✫✞✄✟✏✢✒✣✏✖✠✝ ✟☛✡✩✑✕✢✠✢✒✘ ✞✕✌☛✌☛✞✙✌✬✝ ✟✩✖✕✡☛✔✕✞✒✘ ✈ ✡✏✔✗✞✠✘★✣✗✘ ✖✕✡ ✖✒✥✚✖✠☎ ✌☞✢✕✞✕✱✒✝ ✟✚✞✳✡☛✔✗✞✭✝ ✘✫✞✄✟✏✢✒✣✏✖✠✝ ✟☛✡✩✑✕✢✠✢✒✘ ✞✕✌☛✌☛✞✙✌✬✝ ✟✩✖✕✡☛✔✕✞✒✘ ✪✆✑✏✓✗✌ ✪✆✑✏✓✗✌ .

.

11 29 March, 2002 The Computer Communications Course

TCP/IP Endpoint Address

❨❆✔✕✞ ❨❆✔✕✞ ♠✗❞✙❢☛✉✗✐✙♣✒♣✕❝ ✾★❦ q ✌✏✡☛✘✚✍✗✥✏✡✚✍✕✘ ✞✤❳✆❛✏✍✏✌✗✘✚❛✙✝ ✟✗✥✕☎ ✍✕✢✕✞✙❛✙✟✚✞✙✡✗✝ ✟✚✞✙✡✚❛✒✝ ✟✗✷ ✔✳❭ ✌✏✡☛✘✚✍✗✥✏✡✚✍✕✘ ✞✤❳✆❛✏✍✏✌✗✘✚❛✙✝ ✟✗✥✕☎ ✍✕✢✕✞✙❛✙✟✚✞✙✡✗✝ ✟✚✞✙✡✚❛✒✝ ✟✗✷ ✔✳❭ ✌✗✣✏✞✒✥✙✝ ✱✒✝ ✞✕✌✲✡✏✔✗✞✤❨✆✂✄❩✏❛ ❚ ❩★✞✄✟✏✢✒✣✏✖✠✝ ✟☛✡✩✱✏✖✙✘☛✧✫✑✗✡✗❱ ✌✗✣✏✞✒✥✙✝ ✱✒✝ ✞✕✌✲✡✏✔✗✞✤❨✆✂✄❩✏❛ ❚ ❩★✞✄✟✏✢✒✣✏✖✠✝ ✟☛✡✩✱✏✖✙✘☛✧✫✑✗✡✗❱ ✌✏✡☛✘✚✍✗✥✏✡ ✌✏✡☛✘✚✍✗✥✏✡ ✌☛✖✙✥✕❖☛✑✕✢✒✢✒✘ ✔❃✝ ✟ ✌☛✖✙✥✕❖☛✑✕✢✒✢✒✘ ✔❃✝ ✟ ✿ ✿ ✍✆✔❆✥✏✔✕✑✙✘ ✌✙✝ ✟ ✔❃☎ ✞✄✟✆✕ ✍✆✔❆✥✏✔✕✑✙✘ ✌✙✝ ✟ ✔❃☎ ✞✄✟✆✕ ❛✒❀☞✡✚✖✕✡ ✑✒☎✏✑✕✢✒✢✠✘ ✞✙✌☛✌✬☎ ✞✠✟☛✯✗✡✏✔✠✦✕✢✕✖✒✟ ❛✒❀☞✡✚✖✕✡ ✑✒☎✏✑✕✢✒✢✠✘ ✞✙✌☛✌✬☎ ✞✠✟☛✯✗✡✏✔✠✦✕✢✕✖✒✟ ❁ ❁ ✡★✡ ✖✕✍✕✥✏✔◗✝ ✡✆❂✆❀✙❛ ✡★✡ ✖✕✍✕✥✏✔◗✝ ✡✆❂✆❀✙❛ ✍✆✔❆✥✏✔✕✑✙✘ ✌✙✝ ✟ ✔✭✱✏✑✙✧✲✝ ☎ ✓✏✕ ✍✆✔❆✥✏✔✕✑✙✘ ✌✙✝ ✟ ✔✭✱✏✑✙✧✲✝ ☎ ✓✏✕ ❛✆❀☞✑✕✢✒✢✠✘ ✞✕✌☛✌✲✱✏✑✕✧✎✝ ☎ ✓✬❳ ✜ ✖✏✔ ❚✒❙✘✗ ❨❆❭❃❀✕❛ ❛✆❀☞✑✕✢✒✢✠✘ ✞✕✌☛✌✲✱✏✑✕✧✎✝ ☎ ✓✬❳ ✜ ✖✏✔ ❚✒❙✘✗ ❨❆❭❃❀✕❛ ✍✆✔✭✌✗✔✕✖✙✘ ✡✩✌✙✝ ✟ ✔❆✣☛✖✒✘ ✡✹✕ ✍✆✔✭✌✗✔✕✖✙✘ ✡✩✌✙✝ ✟ ✔❆✣☛✖✒✘ ✡✹✕ ❛✒❀ ✣✏✖✙✘ ✡✎✟☛✍✕✧✲P✗✞✠✘✤❀✕❛ ❛✒❀ ✣✏✖✙✘ ✡✎✟☛✍✕✧✲P✗✞✠✘✤❀✕❛ ✌✏✡☛✘✚✍✕✥☛✡ ✝ ✟ ✔✭✑✕✢✒✢✠✘✫✌✙✝ ✟ ✔✭✑✕✢✒✢✠✘✹✕ ✌✏✡☛✘✚✍✕✥☛✡ ✝ ✟ ✔✭✑✕✢✒✢✠✘✫✌✙✝ ✟ ✔✭✑✕✢✒✢✠✘✹✕ ❛✒❀ ❚ ❩★✑✕✢✒✢✠✘ ✞✙✌☛✌✽❀✙❛ ❛✒❀ ❚ ❩★✑✕✢✒✢✠✘ ✞✙✌☛✌✽❀✙❛ ✥✏✔✕✑✕✘ ✌✙✝ ✟ ✔✛❄☛✞✠✘ ✖✢❅ ❆❈❇ ✕ ✥✏✔✕✑✕✘ ✌✙✝ ✟ ✔✛❄☛✞✠✘ ✖✢❅ ❆❈❇ ✕ ❛✒❀☞✍✙✟☛✍✏✌☛✞✒✢✭✦✗✧✩✍✏✌✏✡✎P✗✞❉❄✏✞✒✘ ✖✘❀✙❛ ❛✒❀☞✍✙✟☛✍✏✌☛✞✒✢✭✦✗✧✩✍✏✌✏✡✎P✗✞❉❄✏✞✒✘ ✖✘❀✙❛ ❊ ✕ ❊ ✕

12 29 March, 2002 The Computer Communications Course

Specifying Endpoint Addresses

✞✒✪✫☎ ✓✬✥✏✘ ✞✕✑✕✡ ✞✒✢✬✌☛✖✙✥✕❖✚✞✒✡★✔✕✑✏✌✬✟✚✖✎✑✗✌☛✌☛✖✙✥✕✝ ✑✗✡✗✝ ✖✒✟★✡✚✖✤☎ ✖✙✥☛✑✒☎✏✖✙✘ ❙ ✞✒✪✫☎ ✓✬✥✏✘ ✞✕✑✕✡ ✞✒✢✬✌☛✖✙✥✕❖✚✞✒✡★✔✕✑✏✌✬✟✚✖✎✑✗✌☛✌☛✖✙✥✕✝ ✑✗✡✗✝ ✖✒✟★✡✚✖✤☎ ✖✙✥☛✑✒☎✏✖✙✘ ✢✕✞✙✌✏✡✗✝ ✟✚✑✕✡✗✝ ✖✒✟★✑✕✢✠✢✒✘ ✞✕✌☛✌✕✷ ✢✕✞✙✌✏✡✗✝ ✟✚✑✕✡✗✝ ✖✒✟★✑✕✢✠✢✒✘ ✞✕✌☛✌✕✷
  • ✰✆✞✒✘✚✜✚✞✒✘✲✣✗✘
✖✙✥✚✞✙✌☛✌☛✞✕✌✎✡☛✔✕✑✗✡✩✖✙✣☛✞✠✘ ✑✗✡ ✞✬✑✗✡✩✑☞✪✆✞✄☎ ☎ ✛ ❖✕✟✚✖✕✪❃✟✲✣✏✖✙✘✚✡★✧✩✍✏✌✏✡✎P✗✞ ✰✆✞✒✘✚✜✚✞✒✘✲✣✗✘ ✖✙✥✚✞✙✌☛✌☛✞✕✌✎✡☛✔✕✑✗✡✩✖✙✣☛✞✠✘ ✑✗✡ ✞✬✑✗✡✩✑☞✪✆✞✄☎ ☎ ✛ ❖✕✟✚✖✕✪❃✟✲✣✏✖✙✘✚✡★✧✩✍✏✌✏✡✎P✗✞ ✑✙P✄☎ ✞✳✡ ✖☞✌✗✣☛✞✠✥✕✝ ✱✏✓☞✡☛✔✕✑✗✡✲✣☛✖✙✘✚✡★✡ ✖☞✡✏✔✗✞✬✌☛✓✗✌✏✡ ✞✒✧✎❱ ✑✙P✄☎ ✞✳✡ ✖☞✌✗✣☛✞✠✥✕✝ ✱✏✓☞✡☛✔✕✑✗✡✲✣☛✖✙✘✚✡★✡ ✖☞✡✏✔✗✞✬✌☛✓✗✌✏✡ ✞✒✧✎❱ P✠✝ ✟✏✢ ❳ ✌✗✢✭✦✳☎ ✖✙✥✚✑✠☎ ✔✭✑✕✢✠✢✒✘✗✦✲✑✕✢✒✢✠✘ ✔❃☎ ✞✠✟✏❭ ✕ ❳ ✌✗✢✭✦✳☎ ✖✙✥✚✑✠☎ ✔✭✑✕✢✠✢✒✘✗✦✲✑✕✢✒✢✠✘ ✔❃☎ ✞✠✟✏❭ ✕
  • ✖✕✖✙✘✩✑☞✥✙☎
✝ ✞✄✟☛✡✗✦✗✡☛✔✗✞✤✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎✏✌☛✖✗✱✗✡✚✪✆✑✙✘ ✞✳✥✗✔✗✖✗✖✗✌✏✞✕✌✬☎ ✖✙✥✚✑✒☎✏✑✕✢✠✢✒✘ ✞✕✌☛✌✲✑✙✟✏✢ ✖✕✖✙✘✩✑☞✥✙☎ ✝ ✞✄✟☛✡✗✦✗✡☛✔✗✞✤✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎✏✌☛✖✗✱✗✡✚✪✆✑✙✘ ✞✳✥✗✔✗✖✗✖✗✌✏✞✕✌✬☎ ✖✙✥✚✑✒☎✏✑✕✢✠✢✒✘ ✞✕✌☛✌✲✑✙✟✏✢ ✣✏✖✙✘✚✡✫✑✕✍✏✡ ✖✙✧✫✑✕✡✗✝ ✥☛✑✒☎ ☎ ✓✙✷ ✣✏✖✙✘✚✡✫✑✕✍✏✡ ✖✙✧✫✑✕✡✗✝ ✥☛✑✒☎ ☎ ✓✙✷ ✜ ✱✕✡ ✞✒✘★✥✗✘ ✞✙✑✗✡✗✝ ✟☛✯✎✑✎✌☛✖✙✥✗❖☛✞✙✡✗✦✏✑✬✥✕☎ ✝ ✞✠✟☛✡✲✥✚✑✠☎ ☎ ✌ ✜ ✱✕✡ ✞✒✘★✥✗✘ ✞✙✑✗✡✗✝ ✟☛✯✎✑✎✌☛✖✙✥✗❖☛✞✙✡✗✦✏✑✬✥✕☎ ✝ ✞✠✟☛✡✲✥✚✑✠☎ ☎ ✌ ❢☛❞✕q✗q✏❧✒❢✄❡ ✡ ✖ ✞✙✌✏✡ ✑✙P✄☎ ✝ ✌✗✔ ✡ ✖ ✞✙✌✏✡ ✑✙P✄☎ ✝ ✌✗✔ ✑✙✟ ✑✙✟ ✑✕✥✏✡✗✝ ✜✚✞✤✘ ✞✄☎ ✝ ✑✙P✄☎ ✞◗P✗✓✕✡ ✞✬✌✏✡☛✘ ✞✕✑✙✧✵✥☛✖✒✟✗✟✚✞✒✥☛✡✕✝ ✖✒✟✲✡ ✖✬✘ ✞✒✧✫✖✕✡✚✞☞✌☛✞✠✘✚✜✚✞✒✘✗❱ ✑✕✥✏✡✗✝ ✜✚✞✤✘ ✞✄☎ ✝ ✑✙P✄☎ ✞◗P✗✓✕✡ ✞✬✌✏✡☛✘ ✞✕✑✙✧✵✥☛✖✒✟✗✟✚✞✒✥☛✡✕✝ ✖✒✟✲✡ ✖✬✘ ✞✒✧✫✖✕✡✚✞☞✌☛✞✠✘✚✜✚✞✒✘✗❱ ✥✚✖✒✟✗✟✚✞✠✥☛✡ ❳ ✌✗✢✭✦✗✢✙✞✕✌✏✡ ✔✭✑✙✢✒✢✒✘✗✦✏✑✕✢✒✢✠✘ ✔✫☎ ✞✠✟✏❭ ✕ ❳ ✌✗✢✭✦✗✢✙✞✕✌✏✡ ✔✭✑✙✢✒✢✒✘✗✦✏✑✕✢✒✢✠✘ ✔✫☎ ✞✠✟✏❭ ✕
slide-3
SLIDE 3

13 29 March, 2002 The Computer Communications Course

Sending and Receiving Data through a Socket

✈ ✟✏✥☛✞☞✑✒✟✩✑✙✣✗✣✒☎ ✝ ✥✚✑✕✡✗✝ ✖✒✟✎✔✗✑✗✌★✞✙✌✏✡ ✑✙P✄☎ ✝ ✌✗✔✗✞✠✢☞✑✎✌☛✖✙✥✕❖✚✞✒✡✗✦✙✝ ✡✲✥✚✑✙✟ ✈ ✟✏✥☛✞☞✑✒✟✩✑✙✣✗✣✒☎ ✝ ✥✚✑✕✡✗✝ ✖✒✟✎✔✗✑✗✌★✞✙✌✏✡ ✑✙P✄☎ ✝ ✌✗✔✗✞✠✢☞✑✎✌☛✖✙✥✕❖✚✞✒✡✗✦✙✝ ✡✲✥✚✑✙✟ ✍✏✌☛✞✳✡☛✔✗✞✬✌☛✖✙✥✕❖✚✞✒✡✩✡ ✖✬✡☛✘ ✑✙✟✚✌✗✧✎✝ ✡❫✑✙✟✏✢✤✘ ✞✒✥☛✞✄✝ ✜☛✞✳✢✙✑✗✡ ✑✒✷ ✍✏✌☛✞✳✡☛✔✗✞✬✌☛✖✙✥✕❖✚✞✒✡✩✡ ✖✬✡☛✘ ✑✙✟✚✌✗✧✎✝ ✡❫✑✙✟✏✢✤✘ ✞✒✥☛✞✄✝ ✜☛✞✳✢✙✑✗✡ ✑✒✷ ✪❀✘✏✝ ✡ ✞ ❳ ✌✗✢✭✦✕P✙✍✏✱✏✱✏✞✒✘✗✦✙P✕✍✏✱✏✱✏✞✒✘ ✔❃☎ ✞✠✟✏❭ ✕ ❳ ✌✗✢✭✦✕P✙✍✏✱✏✱✏✞✒✘✗✦✙P✕✍✏✱✏✱✏✞✒✘ ✔❃☎ ✞✠✟✏❭ ✕ ✘ ✞✕✑✙✢ ❳ ✌✗✢✄✦✙P✙✍☛✱✏✱✏✞✠✘✗✦✕P✙✍✏✱✏✱✏✞✒✘ ✔❃☎ ✞✠✟✗❭ ✕ ❳ ✌✗✢✄✦✙P✙✍☛✱✏✱✏✞✠✘✗✦✕P✙✍✏✱✏✱✏✞✒✘ ✔❃☎ ✞✠✟✗❭ ✕
  • ✁✄✂✆☎
✝ ✂ ✟✞✝ ✰✫✝ ✟✏✥✚✞✤❨✆✂✄❩✬✝ ✌★✑✳P✕✓✕✡ ✞✒✛ ✌✏✡☛✘ ✞✕✑✕✧✮✣✕✘ ✖✕✡ ✖✒✥✚✖✠☎ ✰✫✝ ✟✏✥✚✞✤❨✆✂✄❩✬✝ ✌★✑✳P✕✓✕✡ ✞✒✛ ✌✏✡☛✘ ✞✕✑✕✧✮✣✕✘ ✖✕✡ ✖✒✥✚✖✠☎ ❝✚❧✙✐✕♣✠✟ ✡ ❝✚❧✙✐✕♣✠✟ ✡ ☛ ☛ ✯✄❝✗❦ ❡ ❧☞✟ ✡ ✯✄❝✗❦ ❡ ❧☞✟ ✡ ✥✚✑✒✟✲✘ ✞✙✡✚✍✕✘✏✟★✪✫✝ ✡☛✔◗☎ ✞✙✌☛✌☞P✕✓✕✡ ✞✕✌✎✡☛✔✗✑✒✟☞✝ ✡✩✪❆✑✏✌✎✘ ✞✒✶✏✍✏✞✕✌✏✡✚✞✒✢✠✷ ✥✚✑✒✟✲✘ ✞✙✡✚✍✕✘✏✟★✪✫✝ ✡☛✔◗☎ ✞✙✌☛✌☞P✕✓✕✡ ✞✕✌✎✡☛✔✗✑✒✟☞✝ ✡✩✪❆✑✏✌✎✘ ✞✒✶✏✍✏✞✕✌✏✡✚✞✒✢✠✷ ✥ ✔✕✞✠✟✎✘ ✞✙✑✕✢✄✝ ✟☛✯✗❛✗✪❀✘✗✝ ✡✗✝ ✟☛✯✎✱✕✘ ✖✒✧✫❛✗✡ ✖☞✑☞❨✆✂✄❩✲✌☛✖✙✥✗❖☛✞✙✡ ✥ ✔✕✞✠✟✎✘ ✞✙✑✕✢✄✝ ✟☛✯✗❛✗✪❀✘✗✝ ✡✗✝ ✟☛✯✎✱✕✘ ✖✒✧✫❛✗✡ ✖☞✑☞❨✆✂✄❩✲✌☛✖✙✥✗❖☛✞✙✡ ✐✕❣ ✯✄✐☛♥✏♠ ✐✕❣ ✯✄✐☛♥✏♠ ✍✏✌☛✞ ☎ ✖✗✖✙✣✏❂ ✍✏✌☛✞ ☎ ✖✗✖✙✣✏❂

14 29 March, 2002 The Computer Communications Course

Specifying a Queue Length for a Server

❚ ✱✬✥✚✖✙✧★✣✗✍✏✡✗✝ ✟☛✯✎✑✬✘ ✞✙✌✗✣✏✖✒✟✚✌☛✞✳✡ ✑✙❖☛✞✕✌✬✟✚✖✒✟☛✡☛✘✗✝ ✜✕✝ ✑✒☎✏✑✕✧✫✖✕✍✙✟☛✡✩✖✗✱✎✡✗✝ ✧✫✞✄✦✏✑ ❚ ✱✬✥✚✖✙✧★✣✗✍✏✡✗✝ ✟☛✯✎✑✬✘ ✞✙✌✗✣✏✖✒✟✚✌☛✞✳✡ ✑✙❖☛✞✕✌✬✟✚✖✒✟☛✡☛✘✗✝ ✜✕✝ ✑✒☎✏✑✕✧✫✖✕✍✙✟☛✡✩✖✗✱✎✡✗✝ ✧✫✞✄✦✏✑ ✟✚✞✙✪ ✘ ✞✙✶✗✍☛✞✙✌✏✡✲✧❃✑✗✓✎✑✕✘☛✘✗✝ ✜☛✞✤P✕✞✕✱✏✖✙✘ ✞✬✑✎✌☛✞✒✘✚✜✚✞✠✘✫✱✒✝ ✟✕✝ ✌✗✔✕✞✕✌✎✘ ✞✙✌✗✣☛✖✒✟✏✢✭✝ ✟☛✯ ✟✚✞✙✪ ✘ ✞✙✶✗✍☛✞✙✌✏✡✲✧❃✑✗✓✎✑✕✘☛✘✗✝ ✜☛✞✤P✕✞✕✱✏✖✙✘ ✞✬✑✎✌☛✞✒✘✚✜✚✞✠✘✫✱✒✝ ✟✕✝ ✌✗✔✕✞✕✌✎✘ ✞✙✌✗✣☛✖✒✟✏✢✭✝ ✟☛✯ ✡ ✖☞✑✙✟★✖✠☎ ✢✳✘ ✞✒✶✏✍✏✞✕✌✏✡✗✷ ✡ ✖☞✑✙✟★✖✠☎ ✢✳✘ ✞✒✶✏✍✏✞✕✌✏✡✗✷ ❨❆✔✕✞☞✌✏✞✒✘✚✜✚✞✒✘★✧✫✑✗✓☞✡ ✞✄☎ ☎✏✡☛✔✕✞✳✍✕✟✏✢✙✞✒✘✗☎ ✓✠✝ ✟☛✯✬✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎✏✌☛✖✗✱✗✡✚✪✆✑✙✘ ✞ ❨❆✔✕✞☞✌✏✞✒✘✚✜✚✞✒✘★✧✫✑✗✓☞✡ ✞✄☎ ☎✏✡☛✔✕✞✳✍✕✟✏✢✙✞✒✘✗☎ ✓✠✝ ✟☛✯✬✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎✏✌☛✖✗✱✗✡✚✪✆✑✙✘ ✞ ✡☛✔✕✑✗✡☞✝ ✡★✪✫✝ ✌✕✔✗✞✕✌✎✡ ✖✳✔✗✑✕✜✚✞✳✡☛✔✗✑✕✡★✘ ✞✙✶✗✍✏✞✕✌✏✡✚✌★✞✠✟☛✶✗✍✏✞✙✍✏✞✒✢✳✍✙✟☛✡✗✝ ☎✒✝ ✡✲✔✕✑✏✌✎✡✗✝ ✧✫✞ ✡☛✔✕✑✗✡☞✝ ✡★✪✫✝ ✌✕✔✗✞✕✌✎✡ ✖✳✔✗✑✕✜✚✞✳✡☛✔✗✑✕✡★✘ ✞✙✶✗✍✏✞✕✌✏✡✚✌★✞✠✟☛✶✗✍✏✞✙✍✏✞✒✢✳✍✙✟☛✡✗✝ ☎✒✝ ✡✲✔✕✑✏✌✎✡✗✝ ✧✫✞ ✡ ✖✳✣✗✘ ✖✙✥☛✞✕✌☛✌✎✡☛✔✗✞✠✧✲✷ ✡ ✖✳✣✗✘ ✖✙✥☛✞✕✌☛✌✎✡☛✔✗✞✠✧✲✷ ☎ ✝ ✌✏✡ ✞✠✟ ❳ ✌✗✢✭✦✏✶✒☎ ✞✠✟✏❭ ✕ ❳ ✌✗✢✭✦✏✶✒☎ ✞✠✟✏❭ ✕
  • ✥✚✖✒✟☛✜☛✞✒✘✚✡
✌★✌✏✖✙✥✗❖☛✞✙✡★✡ ✖☞✡☛✔✕✞ ✥✚✖✒✟☛✜☛✞✒✘✚✡ ✌★✌✏✖✙✥✗❖☛✞✙✡★✡ ✖☞✡☛✔✕✞ ❣ ❦ ♠❆❡ ❧✙q✕❦ q r ❣ ❦ ♠❆❡ ❧✙q✕❦ q r ✌☛✖✙✥✗❖☛✞✙✡✩✖✒✟✲✪❀✔✠✝ ✥✏✔◗✝ ✟✏✥✚✖✙✧✎✝ ✟☛✯ ✌☛✖✙✥✗❖☛✞✙✡✩✖✒✟✲✪❀✔✠✝ ✥✏✔◗✝ ✟✏✥✚✖✙✧✎✝ ✟☛✯ ✥✚✖✒✟✗✟☛✞✒✥☛✡✗✝ ✖✒✟✚✌✲✱✕✘ ✖✙✧✮✥✕☎ ✝ ✞✠✟☛✡ ✌☞✥✚✑✒✟✎P✕✞✬✑✕✥✏✥☛✞✒✣✗✡ ✞✒✢ ✥✚✖✒✟✗✟☛✞✒✥☛✡✗✝ ✖✒✟✚✌✲✱✕✘ ✖✙✧✮✥✕☎ ✝ ✞✠✟☛✡ ✌☞✥✚✑✒✟✎P✕✞✬✑✕✥✏✥☛✞✒✣✗✡ ✞✒✢
❣ ❧✙q ✌ ❣ ❧✙q ✌✗✣✏✞✒✥✕✝ ✱✒✝ ✞✙✌✲✡☛✔✕✞✤✧✫✑✗✴✭✝ ✧✩✍✗✧ ✟☛✍✕✧★P✕✞✒✘✩✖✗✱☞✥✙☎ ✝ ✞✄✟☛✡★✥☛✖✒✟✗✟✚✞✒✥✏✡✗✝ ✖✒✟✚✌✎✡☛✔✕✑✗✡ ✌✗✣✏✞✒✥✕✝ ✱✒✝ ✞✙✌✲✡☛✔✕✞✤✧✫✑✗✴✭✝ ✧✩✍✗✧ ✟☛✍✕✧★P✕✞✒✘✩✖✗✱☞✥✙☎ ✝ ✞✄✟☛✡★✥☛✖✒✟✗✟✚✞✒✥✏✡✗✝ ✖✒✟✚✌✎✡☛✔✕✑✗✡ ✡☛✔✕✞◗❖✚✞✠✘☛✟✚✞✭☎✏✪✫✝ ☎ ☎✗✶✏✍✏✞✙✍✏✞✬✱✏✖✙✘ ✡☛✔✕✞◗❖✚✞✠✘☛✟✚✞✭☎✏✪✫✝ ☎ ☎✗✶✏✍✏✞✙✍✏✞✬✱✏✖✙✘✩✡☛✔✕✞✬✌☛✖✙✥✗❖☛✞✙✡ ✍ ✍

15 29 March, 2002 The Computer Communications Course

How a Server accepts Connections

✈ ✟✏✥☛✞☞✑✎✌☛✖✙✥✕❖☛✞✙✡★✔✕✑✏✌✬P✕✞✕✞✠✟★✞✕✌✏✡ ✑✒P✠☎ ✝ ✌✗✔✕✞✒✢✤❳ ✌☛✖✙✥✗❖☛✞✙✡✗✦✙P✄✝ ✟✏✢✄✦✒☎ ✝ ✌✏✡ ✞✠✟✏❭ ✦✏✑✎✌☛✞✒✘✚✜✚✞✠✘ ✈ ✟✏✥☛✞☞✑✎✌☛✖✙✥✕❖☛✞✙✡★✔✕✑✏✌✬P✕✞✕✞✠✟★✞✕✌✏✡ ✑✒P✠☎ ✝ ✌✗✔✕✞✒✢✤❳ ✌☛✖✙✥✗❖☛✞✙✡✗✦✙P✄✝ ✟✏✢✄✦✒☎ ✝ ✌✏✡ ✞✠✟✏❭ ✦✏✑✎✌☛✞✒✘✚✜✚✞✠✘ ✟✚✞✕✞✠✢✕✌✎✡ ✖☞✪✆✑✠✝ ✡✩✱✏✖✙✘✫✑✬✥✚✖✒✟✗✟✚✞✠✥☛✡✗✝ ✖✒✟✗✷✗❨✭✖✳✢✕✖☞✌☛✖✠✦✙✝ ✡✩✍✏✌☛✞✙✌★✌☛✓✗✌✏✡ ✞✠✧✵✥✚✑✠☎ ☎ ✟✚✞✕✞✠✢✕✌✎✡ ✖☞✪✆✑✠✝ ✡✩✱✏✖✙✘✫✑✬✥✚✖✒✟✗✟✚✞✠✥☛✡✗✝ ✖✒✟✗✷✗❨✭✖✳✢✕✖☞✌☛✖✠✦✙✝ ✡✩✍✏✌☛✞✙✌★✌☛✓✗✌✏✡ ✞✠✧✵✥✚✑✠☎ ☎ ✐✕❢✏❢☛❧☛❜✫❡ ✷ ✷
✥☛✑✒☎ ☎✗✡ ✖ ✜ ✥☛✑✒☎ ☎✗✡ ✖ ✐✙❢✏❢☛❧☛❜✫❡ P✠☎ ✖✙✥✕❖✚✌✎✍✙✟☛✡✗✝ ☎✏✑✬✥✚✖✒✟✗✟✚✞✠✥☛✡✗✝ ✖✒✟✲✘ ✞✙✶✗✍✏✞✕✌✏✡✩✑✕✘☛✘✗✝ ✜☛✞✕✌✕✷ P✠☎ ✖✙✥✕❖✚✌✎✍✙✟☛✡✗✝ ☎✏✑✬✥✚✖✒✟✗✟✚✞✠✥☛✡✗✝ ✖✒✟✲✘ ✞✙✶✗✍✏✞✕✌✏✡✩✑✕✘☛✘✗✝ ✜☛✞✕✌✕✷
✔✕✞✠✟★✑✬✥✕☎ ✝ ✞✠✟☛✡☞✝ ✟✕✝ ✡✗✝ ✑✕✡ ✞✕✌✎✡☛✔✕✞✳✥☛✖✒✟✗✟✚✞✒✥✏✡✗✝ ✖✒✟✎❳ ✥ ✔✕✞✠✟★✑✬✥✕☎ ✝ ✞✠✟☛✡☞✝ ✟✕✝ ✡✗✝ ✑✕✡ ✞✕✌✎✡☛✔✕✞✳✥☛✖✒✟✗✟✚✞✒✥✏✡✗✝ ✖✒✟✎❳ ❢✚❞✕q✗q✏❧✠❢✠❡ ❢✚❞✕q✗q✏❧✠❢✠❡ ❭✆✡☛✔✗✞✤❨✆✂✄❩ ❭✆✡☛✔✗✞✤❨✆✂✄❩ ❡ ✭✕❝☛❧✕❧✏✎ ❡ ✭✕❝☛❧✕❧✏✎ ✯✄✐✚♥❉✭✕✐✕q✕♣✏♠✏✭✙✐✗✉✗❧✑✟ ✒✔✓✖✕✘✗✏✡ ✯✄✐✚♥❉✭✕✐✕q✕♣✏♠✏✭✙✐✗✉✗❧✑✟ ✒✔✓✖✕✘✗✏✡ ✣✗✘ ✖✕✡ ✖✒✥✚✖✠☎✒✝ ✌✳✝ ✟✕✝ ✡✗✝ ✑✕✡ ✞✒✢ ✣✗✘ ✖✕✡ ✖✒✥✚✖✠☎✒✝ ✌✳✝ ✟✕✝ ✡✗✝ ✑✕✡ ✞✒✢
✱✚✙ ✥✜✛ ✰ ✝ ✌★✌✏✍✕✥✗✥✚✞✕✌☛✌✏✱✗✍✙☎✏✑✳✟✚✞✙✪ ❨✆✂✄❩✎✥✚✖✒✟✗✟✚✞✠✥☛✡✗✝ ✖✒✟☞✝ ✌★✞✙✌✏✡ ✑✙P✄☎ ✝ ✌✗✔✗✞✠✢☞✑✒✟✏✢ ❚ ✱✚✙ ✥✜✛ ✰ ✝ ✌★✌✏✍✕✥✗✥✚✞✕✌☛✌✏✱✗✍✙☎✏✑✳✟✚✞✙✪ ❨✆✂✄❩✎✥✚✖✒✟✗✟✚✞✠✥☛✡✗✝ ✖✒✟☞✝ ✌★✞✙✌✏✡ ✑✙P✄☎ ✝ ✌✗✔✗✞✠✢☞✑✒✟✏✢ ✐✕❢✗❢✚❧✏❜❃❡ ✐✕❢✗❢✚❧✏❜❃❡ ✘ ✞✙✡☛✍✗✘✏✟✚✌✲✑✬✟☛✞✙✪s✢✙✞✕✌✗✥✗✘✏✝ ✣✏✡✚✖✙✘★❳ ✘ ✞✙✡☛✍✗✘✏✟✚✌✲✑✬✟☛✞✙✪s✢✙✞✕✌✗✥✗✘✏✝ ✣✏✡✚✖✙✘★❳ ❢✚❞✕q✗q✏❧✠❢✠❡ ❧✠♣ ❢✚❞✕q✗q✏❧✠❢✠❡ ❧✠♣ ✢✙✞✕✌✗✥✏✘✗✝ ✣✏✡✚✖✙✘✚❭✭✱✏✖✙✘ ✢✙✞✕✌✗✥✏✘✗✝ ✣✏✡✚✖✙✘✚❭✭✱✏✖✙✘ ✥✚✖✙✧★✧✩✍✙✟✕✝ ✥✚✑✗✡✗✝ ✖✒✟✲✪✫✝ ✡☛✔✬✡☛✔✕✞◗✟✚✞✙✪ ✥✕☎ ✝ ✞✠✟☛✡✲❳ ✥✚✖✙✧★✧✩✍✙✟✕✝ ✥✚✑✗✡✗✝ ✖✒✟✲✪✫✝ ✡☛✔✬✡☛✔✕✞◗✟✚✞✙✪ ✥✕☎ ✝ ✞✠✟☛✡✲❳ ❝☛❧✕✐✕♣☞✟ ✡ ☛ ✯✄❝✗❦ ❡ ❧☞✟ ✡ ❝☛❧✕✐✕♣☞✟ ✡ ☛ ✯✄❝✗❦ ❡ ❧☞✟ ✡ ❭ ❭ ✟✚✞✒✪✆✌☛✖✙✥✗❖ ✡ ✟✚✞✒✪✆✌☛✖✙✥✗❖ ✡ ✑✙✥✏✥☛✞✒✣✗✡ ✑✙✥✏✥☛✞✒✣✗✡ ❳ ✌✗✢✄✦✏✑✕✢✒✢✠✘✗✦☛✑✙✢✒✢✒✘ ✔❃☎ ✞✄✟✏❭ ✕ ❳ ✌✗✢✄✦✏✑✕✢✒✢✠✘✗✦☛✑✙✢✒✢✒✘ ✔❃☎ ✞✄✟✏❭ ✕

16 29 March, 2002 The Computer Communications Course

Servers that handle Multiple Services

✜ ✌☛✞✠✘ ✜✚✞✠✘★✧✫✑✏✓ ✪✆✑✒✝ ✡✩✱✏✖✙✘★✥✚✖✒✟✗✟✚✞✠✥☛✡✗✝ ✖✒✟✚✌★✖✒✟✎✧✩✍✒☎ ✡✗✝ ✣✒☎ ✞✬✌☛✖✙✥✕❖✚✞✒✡ ✌✕✷ ✜ ✌☛✞✠✘ ✜✚✞✠✘★✧✫✑✏✓ ✪✆✑✒✝ ✡✩✱✏✖✙✘★✥✚✖✒✟✗✟✚✞✠✥☛✡✗✝ ✖✒✟✚✌★✖✒✟✎✧✩✍✒☎ ✡✗✝ ✣✒☎ ✞✬✌☛✖✙✥✕❖✚✞✒✡ ✌✕✷ ❨❆✔✕✞☞✌✏✓✏✌✏✡✚✞✒✧✵✥☛✑✒☎ ☎ ✦ ❨❆✔✕✞☞✌✏✓✏✌✏✡✚✞✒✧✵✥☛✑✒☎ ☎ ✦ ♠✗❧✒❣ ❧✒❢✠❡ ✦☛✑✙✣✗✣✒☎ ✝ ✞✕✌✲✡✚✖ ❚ ❛ ✈ ✝ ✟★✯✗✞✠✟✚✞✒✘ ✑✒☎ ✦✕✟✚✖✕✡ ✪ ✍✏✌✏✡✩✡ ✖ ✦☛✑✙✣✗✣✒☎ ✝ ✞✕✌✲✡✚✖ ❚ ❛ ✈ ✝ ✟★✯✗✞✠✟✚✞✒✘ ✑✒☎ ✦✕✟✚✖✕✡ ✪ ✍✏✌✏✡✩✡ ✖ ✥✚✖✙✧★✧✩✍✙✟✕✝ ✥✚✑✗✡✗✝ ✖✒✟★✖✕✜✚✞✒✘✫✌☛✖✙✥✕❖✚✞✒✡ ✌✕✷ ✥✚✖✙✧★✧✩✍✙✟✕✝ ✥✚✑✗✡✗✝ ✖✒✟★✖✕✜✚✞✒✘✫✌☛✖✙✥✕❖✚✞✒✡ ✌✕✷ ✜ ✥☛✑✒☎ ☎✗✡ ✖ ✜ ✥☛✑✒☎ ☎✗✡ ✖ ♠✗❧✠❣ ❧✒❢✄❡ P✄☎ ✖✙✥✗❖☛✌✎✪✆✑✒✝ ✡✗✝ ✟☛✯✎✱✏✖✙✘✩✖✒✟✚✞☞✖✗✱✎✑✎✌☛✞✙✡✩✖✗✱✲✱✠✝ ☎ ✞✤✢✕✞✙✌✗✥✏✘✗✝ ✣✗✡ ✖✙✘ ✌ P✄☎ ✖✙✥✗❖☛✌✎✪✆✑✒✝ ✡✗✝ ✟☛✯✎✱✏✖✙✘✩✖✒✟✚✞☞✖✗✱✎✑✎✌☛✞✙✡✩✖✗✱✲✱✠✝ ☎ ✞✤✢✕✞✙✌✗✥✏✘✗✝ ✣✗✡ ✖✙✘ ✌ ✡ ✖✤P✗✞✠✥✚✖✙✧✫✞✤✘ ✞✙✑✕✢✕✓✠❱ ✡ ✖✤P✗✞✠✥✚✖✙✧✫✞✤✘ ✞✙✑✕✢✕✓✠❱ ✟✏✘ ✞✕✑✙✢✕✓✴✡ ✟✏✘ ✞✕✑✙✢✕✓✴✡ ☞✆✑✢✬ ✑✏✍✂✓ ☞✆✑✢✬ ✑✏✍✂✓ ❳ ✧✫✑✗✴✞✔❆✢✕✞✕✌✗✥✙✦✙✝ ✟ ✔❆✢✕✞✙✌✗✥✕✦✏✖✕✍✗✡ ✔❆✢✕✞✙✌✗✥✕✦✏✞✙✴✠✥✹✔❆✢✕✞✙✌✗✥✕✦✗✡✗✝ ✧✫✞✙✖✕✍✏✡☛❭ ✕ ❳ ✧✫✑✗✴✞✔❆✢✕✞✕✌✗✥✙✦✙✝ ✟ ✔❆✢✕✞✙✌✗✥✕✦✏✖✕✍✗✡ ✔❆✢✕✞✙✌✗✥✕✦✏✞✙✴✠✥✹✔❆✢✕✞✙✌✗✥✕✦✗✡✗✝ ✧✫✞✙✖✕✍✏✡☛❭ ✕

17 29 March, 2002 The Computer Communications Course

Network Byte Order: Big Endian

✛ ❵✭✝ ✯ ✗ ✟✏✢✄✝ ✑✙✟ ❳ ✰❆❩ ✜ ✚✠✂✆✦ ❚ ❵ ✣ ✙✣✢✢✱❆✦✕❩ ❬ ❩✗✛✹✲ ✱✆✦ ✣ ✖✕✡ ✖✒✘ ✖✠☎ ✑✒✦✏✚ ❚ ✰❆✂✄❭ ❱

n n+1 n+2 n+3

Most significant byte Least significant byte

✛ t ✝ ✡✚✡✗☎ ✞ ✗ ✟✏✢✭✝ ✑✙✟ ❳ ❚ ✟☛✡ ✞✄☎ ✦ ✜ ☎ ✣✕✔✗✑✠✦☞✤ ✜❃❯ ✦✕❩ ❬ ❩✗✛✹✲ ✲ ❭ ❱

n n+1 n+2 n+3

Least significant byte Most significant byte

✥ ✣ ✝ ✢✒✢✭☎ ✞ ✗ ✟✏✢✄✝ ✑✒✟ ❳ ✳✠✛ ✙✠✛ ✱✄✛✹✲✆✖✙✘ ✲ ✛ ✱✭✛ ✙✠✛ ✳✒❭

18 29 March, 2002 The Computer Communications Course

BSD UNIX Network Library Calls

  • ✟✚✞✙✡☛✪✆✖✙✘☛❖✬P✗✓✕✡
✞✬✖✙✘☛✢✕✞✒✘★✥☛✖✒✟☛✜✚✞✒✘ ✌✙✝ ✖✒✟✲✘ ✖✕✍✗✡✗✝ ✟✚✞✕✌ ✟✚✞✙✡☛✪✆✖✙✘☛❖✬P✗✓✕✡ ✞✬✖✙✘☛✢✕✞✒✘★✥☛✖✒✟☛✜✚✞✒✘ ✌✙✝ ✖✒✟✲✘ ✖✕✍✗✡✗✝ ✟✚✞✕✌ ☎ ✖✙✥☛✑✒☎ ✔✆✌✗✔✗✖✙✘✚✡✫✡ ☎ ✖✙✥☛✑✒☎ ✔✆✌✗✔✗✖✙✘✚✡✫✡ ✟☛✡ ✖✙✔✗✌ ❳ ✟✚✞✙✡ ✔✭✌✗✔✕✖✙✘✚✡☛❭ ✕ ☎ ✖✙✥✚✑✠☎ ✔❃☎ ✖✒✟☛✯ ✡ ❳ ✟✚✞✙✡ ✔✭✌✗✔✕✖✙✘✚✡☛❭ ✕ ☎ ✖✙✥✚✑✠☎ ✔❃☎ ✖✒✟☛✯ ✡ ✟✏✡ ✖✙✔✠☎ ❳ ✟☛✞✙✡ ✔❃☎ ✖✒✟☛✯✙❭ ✕ ❳ ✟☛✞✙✡ ✔❃☎ ✖✒✟☛✯✙❭ ✕ ✟✚✞✙✡ ✔✭✌✗✔✕✖✙✘✚✡ ✡ ✟✚✞✙✡ ✔✭✌✗✔✕✖✙✘✚✡ ✡ ✔✙✡ ✖✒✟✚✌ ❳ ☎ ✖✙✥☛✑✒☎ ✔✭✌✕✔✗✖✙✘✚✡☛❭ ✕ ✟✚✞✙✡ ✔❃☎ ✖✒✟☛✯ ✡ ❳ ☎ ✖✙✥☛✑✒☎ ✔✭✌✕✔✗✖✙✘✚✡☛❭ ✕ ✟✚✞✙✡ ✔❃☎ ✖✒✟☛✯ ✡ ✔✙✡ ✖✒✟✕☎ ❳ ☎ ✖✙✥☛✑✒☎ ✔❃☎ ✖✒✟☛✯✕❭ ✕ ❳ ☎ ✖✙✥☛✑✒☎ ✔❃☎ ✖✒✟☛✯✕❭ ✕
  • ✑✕✢✠✢✒✘
✞✕✌☛✌☞✧✫✑✙✟✕✝ ✣✏✍✒☎ ✑✕✡✗✝ ✖✒✟✎✘ ✖✙✍✏✡✗✝ ✟✚✞✕✌ ✑✕✢✠✢✒✘ ✞✕✌☛✌☞✧✫✑✙✟✕✝ ✣✏✍✒☎ ✑✕✡✗✝ ✖✒✟✎✘ ✖✙✍✏✡✗✝ ✟✚✞✕✌ ✝ ✣✆✔✭✑✕✢✒✢✠✘✽✡ ✝ ✣✆✔✭✑✕✢✒✢✠✘✽✡ ✝ ✟✚✞✒✡ ✔✭✑✕✢✠✢✒✘ ❳ ✢✕✖✕✡✚✡ ✞✠✢✂✔❆✢✕✞✠✥✕✝ ✧✫✑✒☎ ❭ ✕ ❳ ✢✕✖✕✡✚✡ ✞✠✢✂✔❆✢✕✞✠✥✕✝ ✧✫✑✒☎ ❭ ✕ ✢✙✖✕✡✚✡ ✞✒✢✏✔❆✢✕✞✒✥✙✝ ✧✫✑✠☎✂✡ ✢✙✖✕✡✚✡ ✞✒✢✏✔❆✢✕✞✒✥✙✝ ✧✫✑✠☎✂✡ ✝ ✟✚✞✙✡ ✔❀✟☛✡ ✖✕✑ ❳ ✝ ✣✆✔✭✑✙✢✒✢✒✘☛❭ ✕ ❳ ✝ ✣✆✔✭✑✙✢✒✢✒✘☛❭ ✕
  • ✖✒P✙✡
✑✒✝ ✟✕✝ ✟☛✯✤✝ ✟✚✱✏✖✎✑✒P✗✖✕✍✗✡★✣✕✘ ✖✕✡ ✖✙✥☛✖✠☎ ✌ ✖✒P✙✡ ✑✒✝ ✟✕✝ ✟☛✯✤✝ ✟✚✱✏✖✎✑✒P✗✖✕✍✗✡★✣✕✘ ✖✕✡ ✖✙✥☛✖✠☎ ✌ ✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎ ✔✆✌✏✡☛✘✚✍✗✥✏✡✽✡ ✣✕✘ ✖✕✡ ✖✙✥✚✖✠☎ ✔✆✌✏✡☛✘✚✍✗✥✏✡✽✡ ✯✗✞✙✡☛✣✕✘ ✖✕✡ ✖✒P✗✓✒✟✚✑✙✧❃✞ ❳ ✟✚✑✕✧✫✞✠❭ ✕ ❳ ✟✚✑✕✧✫✞✠❭ ✕
slide-4
SLIDE 4

19 29 March, 2002 The Computer Communications Course

Obtaining Info about Hosts

✔✕✖✗✌✏✡ ✔✆✌✏✡☛✘✚✍✗✥✏✡✽✡ ✔✕✖✗✌✏✡ ✔✆✌✏✡☛✘✚✍✗✥✏✡✽✡ ✯✗✞✙✡☛✔✕✖✗✌✏✡✏P✕✓✙✟✚✑✙✧✫✞ ❳ ✢✕✖✙✧✫✑✠✝ ✟ ✔❀✟✚✑✙✧✫✞✒❭ ✕ ❳ ✢✕✖✙✧✫✑✠✝ ✟ ✔❀✟✚✑✙✧✫✞✒❭ ✕ ✌✏✡☛✘✚✍✕✥☛✡✮✔✕✖✗✌✏✡ ✞✠✟☛✡ ✿ ✥✏✔✕✑✕✘ ❀✙✔✂✔❀✟✚✑✕✧✫✞✰✕ ✥✏✔✕✑✕✘ ❀✙✔✂✔❀✟✚✑✕✧✫✞✰✕ ❛✆❀☞✖✗✱✏✱✒✝ ✥✕✝ ✑✠☎✕✟☛✑✕✧✫✞✬✖✗✱☞✔✕✖✗✌✏✡ ❀✕❛ ❛✆❀☞✖✗✱✏✱✒✝ ✥✕✝ ✑✠☎✕✟☛✑✕✧✫✞✬✖✗✱☞✔✕✖✗✌✏✡ ❀✕❛ ✥✏✔✕✑✕✘ ✥✏✔✕✑✕✘ ❀✂❀ ❀✂❀ ✔✂✔✭✑✠☎ ✝ ✑✗✌☛✞✕✌✒✕ ✔✂✔✭✑✠☎ ✝ ✑✗✌☛✞✕✌✒✕ ❛✆❀☞✑✒☎ ✝ ✑✏✌✳☎ ✝ ✌✗✡✤❀✙❛ ❛✆❀☞✑✒☎ ✝ ✑✏✌✳☎ ✝ ✌✗✡✤❀✙❛ ✝ ✟☛✡ ✔✒✔✭✑✙✢✒✢✒✘✚✡ ✓✙✣✏✞✞✕ ✝ ✟☛✡ ✔✒✔✭✑✙✢✒✢✒✘✚✡ ✓✙✣✏✞✞✕ ❛✆❀✳✔✕✖✗✌✏✡✫✑✙✢✒✢✒✘ ✞✕✌✏✌✲✡ ✓✙✣✏✞ ❀✙❛ ❛✆❀✳✔✕✖✗✌✏✡✫✑✙✢✒✢✒✘ ✞✕✌✏✌✲✡ ✓✙✣✏✞ ❀✙❛ ✝ ✟☛✡ ✔✒✔❃☎ ✞✠✟☛✯✗✡✏✔✏✕ ✝ ✟☛✡ ✔✒✔❃☎ ✞✠✟☛✯✗✡✏✔✏✕ ❛✒❀✤☎ ✞✠✟☛✯✗✡☛✔✬✖✗✱✲✑✒✟✩✑✕✢✠✢✒✘ ✞✕✌☛✌✫❀✕❛ ❛✒❀✤☎ ✞✠✟☛✯✗✡☛✔✬✖✗✱✲✑✒✟✩✑✕✢✠✢✒✘ ✞✕✌☛✌✫❀✕❛ ✥✗✔✗✑✙✘ ✥✗✔✗✑✙✘ ❀✏❀ ❀✏❀ ✔✂✔✭✑✕✢✒✢✠✘ ✔❃☎ ✝ ✌✏✡✆✕✤❛✆❀ ✔✂✔✭✑✕✢✒✢✠✘ ✔❃☎ ✝ ✌✏✡✆✕✤❛✆❀ ☎ ✝ ✌✏✡✩✖✗✱✲✑✙✢✒✢✒✘ ✞✕✌☛✌☛✞✙✌★✱✕✘ ✖✙✧ ✟✚✑✕✧✫✞✬✌☛✞✒✘✚✜✚✞✒✘ ❀✕❛ ☎ ✝ ✌✏✡✩✖✗✱✲✑✙✢✒✢✒✘ ✞✕✌☛✌☛✞✙✌★✱✕✘ ✖✙✧ ✟✚✑✕✧✫✞✬✌☛✞✒✘✚✜✚✞✒✘ ❀✕❛
  • ✢✙✞✕✱✒✝
✟✚✞
  • ✢✙✞✕✱✒✝
✟✚✞ ✔✂✔✭✑✙✢✒✢✒✘ ✔✂✔✭✑✙✢✒✢✒✘ ✔✒✔✆✑✕✢✒✢✠✘ ✔✫☎ ✝ ✌✏✡✏❅ ✱✠❇ ✔✒✔✆✑✕✢✒✢✠✘ ✔✫☎ ✝ ✌✏✡✏❅ ✱✠❇ ❛✆❀☞✱✒✝ ✘ ✌✏✡ ❚ ❩✲✑✕✢✒✢✒✘ ✞✙✌☛✌✽❀✙❛ ❛✆❀☞✱✒✝ ✘ ✌✏✡ ❚ ❩✲✑✕✢✒✢✒✘ ✞✙✌☛✌✽❀✙❛ ❊ ✕ ❊ ✕

20 29 March, 2002 The Computer Communications Course

Using Socket Calls in A Program

socket() bind() listen() accept() read() write() close() socket() connect() write() read()

Connection establishment Data (request) Data (reply)

Client: Server:

close()

End-of-file notification 21 29 March, 2002 The Computer Communications Course

Our First Socket Program

✌✙✝ ✧★✣✙☎ ✞✤❨✆✂✄❩✎✢✙✑✏✓✙✛ ✡✕✝ ✧✫✞✤✥✕☎ ✝ ✞✠✟☛✡✚❛✏✌☛✞✒✘✚✜✚✞✒✘✗❱ ✜ ✌✙✝ ✧★✣✙☎ ✞✤❨✆✂✄❩✎✢✙✑✏✓✙✛ ✡✕✝ ✧✫✞✤✥✕☎ ✝ ✞✠✟☛✡✚❛✏✌☛✞✒✘✚✜✚✞✒✘✗❱
  • ✂✆☎
✝ ✞✠✟☛✡✗❱✗✞✕✌✏✡✚✑✙P✄☎ ✝ ✌✗✔✕✞✕✌✲✑✬❨✆✂✄❩✎✥✚✖✒✟✗✟✚✞✠✥☛✡✗✝ ✖✒✟★✪✫✝ ✡☛✔☞✑✎✌☛✞✒✘✚✜✚✞✠✘ ✂✆☎ ✝ ✞✠✟☛✡✗❱✗✞✕✌✏✡✚✑✙P✄☎ ✝ ✌✗✔✕✞✕✌✲✑✬❨✆✂✄❩✎✥✚✖✒✟✗✟✚✞✠✥☛✡✗✝ ✖✒✟★✪✫✝ ✡☛✔☞✑✎✌☛✞✒✘✚✜✚✞✠✘
  • ✰✆✞✒✘✚✜✚✞✒✘✗❱✗✑✕✥✗✥✚✞✠✣✏✡
✌✎✡☛✔✕✞✳✥☛✖✒✟✗✟✚✞✒✥✏✡✗✝ ✖✒✟★✑✙✟✏✢✬✌☛✞✠✟✗✢✕✌☞P✕✑✕✥✕❖✲✡☛✔✕✞✳✥✏✍✕✘✚✘ ✞✠✟☛✡ ✰✆✞✒✘✚✜✚✞✒✘✗❱✗✑✕✥✗✥✚✞✠✣✏✡ ✌✎✡☛✔✕✞✳✥☛✖✒✟✗✟✚✞✒✥✏✡✗✝ ✖✒✟★✑✙✟✏✢✬✌☛✞✠✟✗✢✕✌☞P✕✑✕✥✕❖✲✡☛✔✕✞✳✥✏✍✕✘✚✘ ✞✠✟☛✡ ✡✗✝ ✧✫✞☞✑✒✟✏✢✳✢✙✑✗✡ ✞ ✝ ✟✲✔✙✍✗✧✫✑✒✟✲✘ ✞✕✑✙✢✕✑✙P✄☎ ✞✬✱✏✖✙✘☛✧ ✡✗✝ ✧✫✞☞✑✒✟✏✢✳✢✙✑✗✡ ✞ ✝ ✟✲✔✙✍✗✧✫✑✒✟✲✘ ✞✕✑✙✢✕✑✙P✄☎ ✞✬✱✏✖✙✘☛✧ ❲ ❲ ✝ ✡✚✞✒✘ ✑✗✡✗✝ ✜✚✞✄❱✗✌☛✞✠✘ ✜✚✞✙✌★✖✒✟✕☎ ✓✎✑✎✌✙✝ ✟☛✯✠☎ ✞✤✥✕☎ ✝ ✞✠✟☛✡✩✑✗✡✩✑✎✡✕✝ ✧✫✞ ✝ ✡✚✞✒✘ ✑✗✡✗✝ ✜✚✞✄❱✗✌☛✞✠✘ ✜✚✞✙✌★✖✒✟✕☎ ✓✎✑✎✌✙✝ ✟☛✯✠☎ ✞✤✥✕☎ ✝ ✞✠✟☛✡✩✑✗✡✩✑✎✡✕✝ ✧✫✞

22 29 March, 2002 The Computer Communications Course

1 int main(int argc, char **argv) { 4 int sockfd, n; 5 char recvline[MAXLINE + 1]; 6 struct sockaddr_in servaddr; 8 sockfd = socket(PF_INET, SOCK_STREAM, 0); 9 bzero(&servaddr, sizeof(servaddr)); 10 servaddr.sin_family = AF_INET; 11 servaddr.sin_port = htons(13); /* daytime server */ 12 inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 13 connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)); 14 while ( (n = read(sockfd, recvline, MAXLINE)) > 0) { 15 recvline[n] = ‘\0’; /* null terminate */ 16 fputs(recvline, stdout); 17 } 18 exit(0); 19 }

Day-Time TCP Client

23 29 March, 2002 The Computer Communications Course

Day-Time TCP Server

1 int main(int argc, char **argv) { 2 int listenfd, connfd; 3 struct sockaddr_in servaddr; 4 char buff[MAXLINE]; 5 time_t ticks; 6 6 7 7 listenfd = socket(PF_INET, SOCK_STREAM, 0); 8 bzero(&servaddr, sizeof(servaddr)); 9 servaddr.sin_family = AF_INET; 10 servaddr.sin_addr.s_addr = htonl(INADDR_ANY); 11 servaddr.sin_port = htons(13); /* daytime server */

24 29 March, 2002 The Computer Communications Course

Day-Time TCP Server (contd)

12 bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr)); 13 listen(listenfd, LISTENQ); 14 15 for ( ; ; ) { 16 connfd = accept(listenfd, (struct sockaddr *) NULL, NULL); 17 ticks = time(NULL); 18 snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks)); 19 write(connfd, buff, strlen(buff)); 20 close(connfd); 21 } 22 }

slide-5
SLIDE 5

25 29 March, 2002 The Computer Communications Course

Further Info Sources

  • ✧✫✑✙✟✎✣✏✑✗✯✏✞✙✌
✧✫✑✙✟✎✣✏✑✗✯✏✞✙✌
  • ❛✏✍✏✌✗✘✚❛✙✝
✟✏✥✕☎ ✍✗✢✕✞✒❛ ❛✏✍✏✌✗✘✚❛✙✝ ✟✏✥✕☎ ✍✗✢✕✞✒❛ ❲ ❲ ✌☛✓✗✌✏❛✏✡ ✓✙✣✏✞✕✌✕✷ ✔ ✌☛✓✗✌✏❛✏✡ ✓✙✣✏✞✕✌✕✷ ✔ ❲ ❲ ✌☛✓✗✌✏❛☛✌☛✖✙✥✕❖☛✞✙✡✏✷ ✔ ✌☛✓✗✌✏❛☛✌☛✖✙✥✕❖☛✞✙✡✏✷ ✔ ❲ ❲ ✟✚✞✙✡✕✝ ✟✚✞✙✡☛❛✙✝ ✟✗✷ ✔ ✟✚✞✙✡✕✝ ✟✚✞✙✡☛❛✙✝ ✟✗✷ ✔ ❲ ❲ ✟✚✞✙✡✏✢✠P✒✷ ✔ ✟✚✞✙✡✏✢✠P✒✷ ✔