• No results found

Computer Networks. The Socket API (Project 1) & Traceroute (HW 1)

N/A
N/A
Protected

Academic year: 2021

Share "Computer Networks. The Socket API (Project 1) & Traceroute (HW 1)"

Copied!
24
0
0

Loading.... (view fulltext now)

Full text

(1)

Computer Networks

The Socket API (Project 1) & Traceroute (HW 1)

Originally By David Wetherall (djw@)

(2)

Outline

Ø

Administrivia

Ø

Project 1 and Socket API

(3)

Administrivia

Computer Networks 3

Ø

Sections will be recorded

Ø

HW1 & Traceroute Experiment due tomorrow

Ø

HW2 due Jan 21

st

(next Friday)

(4)

Network-Application Interface

Ø

Defines how apps use the network

Ø Application Layer APIs

Ø Lets apps talk to each other

Ø hides the other layers of the network

app

app

(5)

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

Client

Time

Server

Computer Networks

request

reply

extract

information

request

Continue…

(6)

Project 1

Ø

This is the basis for many apps!

Ø File transfer: send name, get file Ø Web browsing: send URL, get page Ø Echo: send message, get it back Ø Let’s see how to write this app …

(7)

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

(8)

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

(9)

Socket API (3)

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 7

Primitive

Meaning

SOCKET

Create a new communication endpoint

BIND

Associate a local address (port) 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

(10)

Using TCP Sockets (2)

Client (host 1)

Time

Server (host 2)

request

reply

disconnect

1

1

2

3

connect

(11)

Using TCP Sockets (3)

Client (host 1)

Time

Server (host 2)

5: connect*

1: socket

9: send

6: recv*

7: send

8: recv*

11: close

request

Computer Networks 11

reply

disconnect

connect

*= call blocks

1: socket

2: (bind)

3: (listen)

4: accept*

10: recv*

12: close

(12)

Using UDP Sockets

Client (host 1)

Time

Server (host 2)

5: connect*

1: socket

9: sendto

6: recvfrom*

7: sendto

8: recvfrom*

request

reply

disconnect

connect

*= call blocks

1: socket

2: (bind)

3: (listen)

4: accept*

10: recvfrom*

(13)

Client Program (outline)

Computer Networks 13

socket()

// make socket

getaddrinfo() // server and portname

// www.example.com:80

connect() // connect to server [block]

send()

recv()

close()

// send request

// await reply [block]

// do something with data!

(14)

Server Program (outline)

socket() // make socket

getaddrinfo() // for port on this host // associate port with socket // prepare to accept connections // wait for a connection [block] bind() listen() accept() … recv() … send() close()

// wait for request [block] // send the reply

(15)

Java Examples with Socket & ServerSocket

Computer Networks 15

Ø

Server

• http://cs.lmu.edu/~ray/notes/javanetexamples/ • https://docs.oracle.com/javase/tutorial/net working/datagrams/clientServer.html • https://docs.oracle.com/javase/tutorial/net working/sockets/index.html

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();

(16)

Traceroute

Ø

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

(17)

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 15

: Credit: Wikipedia (public domain)

(18)

Traceroute

Ø

Probes successive hops to find network path

Ø

Core mechanism: Time-To-Live(TTL)

Ø

TTL == 0?

Discard data, error (ICMP) report to sender

Continue with TTL-1

Local

(19)

Traceroute

. . .

Local

Host

1 hop

2 hops

3 hops

N-1 hops

N hops

Remote

Host

Computer Networks 19

(20)
(21)

Using

Traceroute

21

(22)

Using Traceroute

Router settings

affect results

(23)

Using Traceroute (2)

Ø

ISP names and places are educatedguesses

My computer

www.uw.edu

(www1.cac.washington.edu)

Level3 pnw-gigapop

UW

6 hops

1 hop

3 hops

. . .

tde Telefonica

3 hops

4 hops

100 ms

180 ms

NYC

San Jose

Computer Networks 23

UW

>200 ms

Seattle

Home

1 hop

(24)

END

© 2013 D. Wetherall

References

Related documents

Atomistic simulations using the quasicontinuum method are used to study the role of vacancy defects and angström-scale voids on the mechanical behavior of five tilt bicrys-

LJMU is committed to providing research students with relevant and appropriate opportunities to develop both specialist and generic research skills in line with its Researcher

My father´s name is Robert, he Works as a police- man so he has to gets-up My father´s name is Robert, he Works as a police- man so he has to gets-up very early every day, he is

Option 3 does not create a new regulatory environment for the independent healthcare sector, as the use of electronic signatures, and the subsequent electronic transmission

The assessment of patients suspected of drug and/or alcohol dependency and the assessment of victims of abuse and neglect are shaped by the culture of the patient population.

Melodic knowledge is focused on the ability of systems in choosing and arranging notations that fit the characteristic sound of gamelan melody. Notation pattern recognition

If either side make three consecutive fouls it shall count as a goal for the opponents consecutive means without the opponents in the meantime making a foul.. Goal shall be made

Left-behind workers share space with large minority communities who were drawn to the inner city, often in the later phases of industrial growth, to perform the jobs