Post on 04-Jan-2016
4061 Session 25 (4/17)
Today
• Briefly: Select and Poll
• Layered Protocols and the Internets
• Intro to Network Programming
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
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
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
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
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
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
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
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)
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
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
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
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)
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
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