Академический Документы
Профессиональный Документы
Культура Документы
Network-Application Interface
Defines how apps use the network
Lets apps talk to each other via hosts;
hides the details of the network
app
host
Computer Networks
app
host
2
Motivating Application
Simple client-server setup
request
reply
Computer Networks
Socket API
Simple abstraction 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
Computer Networks
Socket,
Port #1
Computer Networks
Socket,
Port #2
Computer Networks
Meaning
Create a new communication endpoint
Associate a local address with a socket
Announce willingness to accept connections; give queue size
Passively establish an incoming connection
Actively attempt to establish a connection
Send some data over the connection
Receive some data from the connection
Release the connection
Using Sockets
Client (host 1) Time Server (host 2)
Computer Networks
connect
1
2
1
request
reply
4
Computer Networks
disconnect
3
4
9
1: socket
2: bind
3: listen
4: accept*
5: connect*
request
7: send
8: recv*
10: close
Computer Networks
6: recv*
reply
9: send
disconnect
10: close
*= call blocks
10
send()
recv()
close()
Computer Networks
// make socket
// server and port name
// www.example.com:80
// connect to server [block]
// send request
// await reply [block]
// do something with data!
// done, disconnect
11
recv()
send()
close()
Computer Networks
// make socket
// for port on this host
// associate port with socket
// prepare to accept connections
// wait for a connection [block]
// wait for request
// send the reply
// eventually disconnect
12
END
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
Computer Networks
13