computer networks - university of washington · computer networks 3 about me i’m john! senior in...
TRANSCRIPT
![Page 1: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/1.jpg)
Computer NetworksThe Socket API (Project 1) & Traceroute (HW 1)
(§1.3.4, 6.1.2-6.1.4)
Originally By David Wetherall (djw@), Modified By Bradford Chen (bradchen@)
![Page 2: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/2.jpg)
About Me
Computer Networks 2
I’m Brad!
Senior in CSE
I love distributed systems and network programming
This is my 2nd quarter as a TA
Interned at Amazon and Snowflake in the past
![Page 3: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/3.jpg)
Computer Networks 3
About Me
Computer Networks 3
I’m John!
Senior in CSE
I too love distributed systems, OS, and network programming
This is my 2nd quarter as a TA
Planning to join AWS in August
![Page 4: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/4.jpg)
Network-Application Interface
Defines how apps use the network
Application LayerAPIs
Lets apps talk to each other
hides the other layers of the network
11Computer Networks
host
appapp
host
network
![Page 5: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/5.jpg)
Project 1
Computer Networks 5
Simple Client
Send requests to attu server
Wait for a reply
Extract the information from the reply
Continue…
Simple Server
Server handles the Client requests
Multi-threaded
![Page 6: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/6.jpg)
Project 1
Computer Networks 6
This is the basis for many apps!
File transfer: send name, get file (§6.1.4)
Web browsing: send URL, get page
Echo: send message, get it back
Let’s see how to write this app …
![Page 7: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/7.jpg)
Socket API (Generalized)
Computer Networks 7
Simple application-layer abstractions (APIs) to use the network
The network service API used to write all Internet
applications
Part of all major OSes and languages; originally Berkeley
(Unix) ~1983
Two kinds of sockets
Streams (TCP): reliably send a stream of bytes
Datagrams (UDP): unreliably send separate messages
![Page 8: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/8.jpg)
Socket API (2)
Sockets let apps attach to the local network at
different ports
Ports are used by OS to distinguish services/apps
using internet
Socket
Port 1
Socket
Port 2
Computer Networks 8
![Page 9: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/9.jpg)
Socket API (3)
16
Primitive Meaning
SOCKET Create a new communication endpoint
BIND Associate a local address (port) with a socket
LISTENAnnounce 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
Computer Networks
https://docs.oracle.com/javase/8/docs/api/java/net/Socket.html
https://docs.oracle.com/javase/8/docs/api/java/net/ServerSocket.html
![Page 10: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/10.jpg)
Using Sockets
Client (host 1) Time Server (host 2)
Computer Networks 10
![Page 11: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/11.jpg)
Using Sockets (2)
Client (host 1) Time Server (host 2)
request
Computer Networks 11
reply
1 1
2
3
disconnect44
connect
![Page 12: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/12.jpg)
Using Sockets (3)
Client (host 1) Time Server (host 2)
5: connect*
1: socket
6: recv*
1: socket
2: (bind)3: (listen)
4: accept*
7: send
8: recv*
10: close
9: send
10: close
request
Computer Networks 12
reply
disconnect
connect
*= call blocks
![Page 13: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/13.jpg)
Client Program (outline)
Computer Networks 13
socket() // make socket
getaddrinfo() // server and port name
// www.example.com:80
connect() // connect to server [block]
…
send()
recv()
…
close()
// send request
// await reply [block]
// do something with data!
// done, disconnect
![Page 14: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/14.jpg)
Server Program (outline)
Computer Networks 14
socket() // make socket
getaddrinfo() // for port on this host
// associate port with socket
// prepare to accept connections
// wait for a connection [block]
// wait for request
bind()
listen()
accept()
…
recv()
…
send()
close()
// send the reply
// eventually disconnect
![Page 15: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/15.jpg)
Java Examples with Socket & ServerSocket
Computer Networks 15
• http://cs.lmu.edu/~ray/notes/javanetexampl
es/
• https://docs.oracle.com/javase/tutorial/net
working/datagrams/clientServer.html
• https://docs.oracle.com/javase/tutorial/net
working/sockets/index.html
Server Client
ServerSocket listener = new ServerSocket(9090);
try {
while (true) {
Socket socket = listener.accept();
try {
socket.getInputStream();
} finally {
socket.close();
}
}
}
finally {
listener.close();
}
Socket socket = new Socket(server, 9090);
out =
new PrintWriter(socket.getOutputStream(), true);
socket.close();
![Page 16: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/16.jpg)
Questions?
![Page 17: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/17.jpg)
Traceroute
host
Apps talk to other apps with no real idea of what is inside
the network
This is good! But you may be curious …
Peeking inside the Network with Traceroute
app app
host
???
![Page 18: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/18.jpg)
Traceroute
Widely used command-line tool to let hosts peek inside
the network
On all OSes (tracert on Windows)
Developed by Van Jacobson ~1987
Uses a network-network interface (IP) in ways we
will explain later
Computer Networks 6
: Credit: Wikipedia (public domain)
Van Jacobson
![Page 19: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/19.jpg)
Traceroute
Probes successive hops to find network
path
TTL: time-to-live
7
. . .
LocalCHompoutesr Ntetworks
Remote
Host
![Page 20: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/20.jpg)
Traceroute
. . .
Local
Host
1 hop2 hops
3 hops N-1 hopsN hops
Remote
Host
Computer Networks 20
![Page 21: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/21.jpg)
Using Traceroute
Computer Networks 21
![Page 22: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/22.jpg)
Using Traceroute (2)
ISP names and places are educatedguesses
My computer
tde Telefonica
3 hops 4 hops
Level3 pnw-gigapop UW 6 hops 1 hop 3 hops
Home
1 hop
. . .
100 ms180 ms
NYC San Jose
Computer Networks 22
UW
>200 ms
Seattle www.uw.edu
(www1.cac.washington.edu)
![Page 23: Computer Networks - University of Washington · Computer Networks 3 About Me I’m John! Senior in CSE I too love distributed systems, OS, and network programming This is my 2nd quarter](https://reader034.vdocument.in/reader034/viewer/2022051822/5fecdc407bbba5000c536aa7/html5/thumbnails/23.jpg)
END
Computer Networks 23
© 2013 D. Wetherall
Slide material from: TANENBAUM, ANDREW S.; WETHERALL, DAVID J., COMPUTER NETWORKS, 5th
Edition, © 2011. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle
River, New Jersey