Lecture 2
Lecture 2
1
Previously …
• Network Components
– Apps, Nodes, Links
2
Network
app
router link
host
3
Key Interfaces
1. Network-application interfaces define how apps use
the network
– Sockets are widely used in practice
– Lets apps talk to each other via hosts; hides the details of
the network
app
host
4
Motivating Application
• Simple client-server setup
– Client app sends a request to server app
– Server app returns a (longer) reply
Primitive Meaning
SOCKET Create a new communication endpoint
BIND Associate a local address with a socket
LISTEN Announce willingness to accept connections; give queue size
ACCEPT Passively establish an incoming connection
CONNECT Actively attempt to establish a connection
SEND Send some data over the connection
RECEIVE Receive some data from the connection
CLOSE Release the connection 7
Using Sockets
Client (host 1) Time Server (host 2)
1: socket
1: socket 2: bind
connect 3: listen
4: accept*
5: connect*
request 6: recv*
7: send
8: recv* reply
9: send
disconnect
10: close 10: close *= call blocks
8
Server Program (stream)
9
Server Program (stream)
10
Server Program (stream)
11
Server Program (stream)
12
Client Program (stream)
13
Client Program (stream)
14
Client Program (stream)
15
Run Server/Client
• Commend line for server
– ./server.out 100
• Commend line for client
– ./client.out chenmingzhes-MacBook-Pro.local 100
16
Socket (Datagrams)
• Datagrams (UDP) are (a little) different
Create
Receive
Send
Connectionless
• Useful references
– http://www.linuxhowtos.org/C_C++/socket.htm
– https://www.cs.rutgers.edu/~pxk/417/notes/sockets/udp.
html
17
Key Interfaces
2. Network-network interfaces define how nodes work
together
– Traceroute can peek in the network
app
host
18
Traceroute
• Widely used command-line tool to let hosts peek
inside the network
– On all OSes (tracert on Windows)
...
1 hop 2 hops 3 hops N-1 hops
N hops
Local Remote
Host Host 19
Using Traceroute
Traceroute sends out three packets per TTL increment. Each column corresponds to
the time took to get one packet back (RTT)
20
Protocols and Layers
• The network does much for apps
– Make and break connections
– Find a path through the network
– Transfers information reliably
– Transfers arbitrary length information
– Send as fast as the network allows
– Shares bandwidth among users
– Secures information in transit
– Let many new hosts be added
– …
21
Protocols and Layers
• Protocols and layering is the main structuring method used to
divide up network functionality
– Each instance of a protocol talks virtually to its peer using the protocol
– Each instance of a protocol uses only the services of the lower layer
Node 1 Node 2
22
Protocols and Layers
• A list of protocols in use is called a protocol stack
23
Protocols and Layers
• Protocols you’ve probably heard of
– TCP, IP, 802.11, Ethernet, HTTP, SSL, DNS, … and
many more
Browser
24