4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to...
-
Upload
griffin-randall -
Category
Documents
-
view
217 -
download
2
Transcript of 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to...
![Page 1: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/1.jpg)
4061 Session 25 (4/17)
![Page 2: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/2.jpg)
Today
• Briefly: Select and Poll
• Layered Protocols and the Internets
• Intro to Network Programming
![Page 3: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/3.jpg)
Today’s Objectives• Understand enough networking to get
going with sockets programming
• Compare Berkeley Sockets with other forms of IPC
• Write simple code for a network client
![Page 4: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/4.jpg)
Race Conditions in Select
• Question from last time
• Answer: yes, there may be race conditions if multiple processes are interacting with the same I/O channels.
• Example
![Page 5: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/5.jpg)
Network Programming
• Obviously, much of what we do these days involves different computers talking with one another– These computers may be physically
copresent or separated by oceans
![Page 6: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/6.jpg)
System Calls for Networking
• Again, we are interested in understanding the system calls which the OS provides, such as calls to:– connect to another machine– send/receive data
![Page 7: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/7.jpg)
Scope: Networking Info
• We will skip the technical details of how networking is implemented– Take 4211 (etc.) or read a networking book
for more info
• But there are a few details that we all should know
![Page 8: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/8.jpg)
Abstraction Design Goals
• A machine may be connected to a network with a WIFI connection, or with an ethernet connection– We do not want to have to write code for each
case
• Similarly, there are several other features that we want to work automatically– Routing– Error Checking
![Page 9: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/9.jpg)
Layered Protocols
• To get this abstraction, networks are organized as a stack of layers– Each layer provides a service to the layer above
(shielding that layer from implementation details)– Each layer is built on the layer below (using the
services provided)
• Layer n on one machine transacts with layer n on another machine– By way of a protocol: the rules and conventions used
in an abstraction layer
![Page 10: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/10.jpg)
![Page 11: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/11.jpg)
![Page 12: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/12.jpg)
![Page 13: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/13.jpg)
IP Layer
• Unique global addressing– Ensure that two computers on the Internet can
identify one another
• IPv4– 32 bit (4 byte) addresses (~4 billion)– E.g., the U of M’s Web server has the address
64.233.167.99
• Makes no guarantees about correctness or arrival (leaves that to upper layers)
![Page 14: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/14.jpg)
Transport Layer
• Responsible for– end-to-end connection– error recovery– ensuring complete data transfer
• TCP– Connections, reliable, in-order delivery– Example apps: www, email, ssh
• UDP– Connectionless, unreliable, out-of-order, fast– Example apps: VoIP, online games
![Page 15: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/15.jpg)
Routing
• A path between two computers is a series of hops– Connected by routers, computers whose job
is to figure out where your information should go in the next hop (to get it closer to its destination)
• The unit of information that’s routed is called a packet
• Different packets may take different routes
![Page 16: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/16.jpg)
Ports
• An IP address identifies a machine, while a port identifies a communication endpoint
• One machine may serve both ssh and www…to allow this, sshd and httpd each bind themselves to a different port
• There are well-known ports (below #1024):– http: 80– https: 443– ftp: 21
• On linux, /etc/services
![Page 17: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/17.jpg)
Internet Sockets
• An Internet Socket (or just “socket”) is an endpoint for communication– It is associated with an IP address and port– It is associated with a protocol on the
transport layer of TCP/IP (usually TCP or UDP)
![Page 18: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/18.jpg)
Berkeley Sockets API
• An API for communications via ports• Designed to allow C programmers to
perform IPC across networks• Released in 1983• Still standard API, replicated on many
modern platforms and languages– Windows XP (winsock is based on BSD
sockets)– Python
![Page 19: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/19.jpg)
Berkeley Sockets API
• Bi-directional (contrast with pipes) and full-duplex
• Can be used to perform IPC between processes on a single machine, or over a network
• telnet: open a socket from the command line
![Page 20: 4061 Session 25 (4/17). Today Briefly: Select and Poll Layered Protocols and the Internets Intro to Network Programming.](https://reader035.fdocuments.in/reader035/viewer/2022062517/56649f115503460f94c24cc7/html5/thumbnails/20.jpg)