+ All Categories
Home > Documents > The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that...

The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that...

Date post: 03-Aug-2020
Category:
Upload: others
View: 4 times
Download: 0 times
Share this document with a friend
30
The Internet and Java Sockets ICW Lecture 5 Tom Chothia
Transcript
Page 1: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

The Internet and Java Sockets

ICW Lecture 5 Tom Chothia

Page 2: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

Reminder of Last Time:

•  How does Java actually work. –  Byte code, JVMs, Classpaths, ...

•  The Crypto API

•  A short history of Java – What was added when –  and what’s coming next.

Page 3: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

This Time:

•  How the Internet works. – Some History – TCP/IP – DNS

•  How to make socket connections between computers using Java.

•  How to send Strings and Objects.

Page 4: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

Before the Internet

•  Life was solitary, poor, nasty, brutish and short.

•  Computer Networks: – local networks, – telephone line connections, – leased line.

Page 5: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

The Start 1969

•  The US Defense Advanced Research Projects Agency (then ARPA now DARPA) gives research grants to universities to buy computers.

•  The decide to link their computers.

•  But how?

Page 6: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

But if everyone just sends a small packet of data, they can both use the

line at the same.

A

B D

C

Page 7: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens
Page 8: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

The Internet Protocol Packet

Page 9: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

IP Addresses

•  Every computer has an IP address. e.g. 147.188.193.15

•  Every router on the Internet keeps a list of which connection it should use for which addresses.

Page 10: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens
Page 11: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens
Page 12: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

Transmission Control Protocol

•  1974: daily traffic more than 3 million packets a day. Many are getting lost.

•  TCP is a protocol than runs on top on IP, if an IP packet gets lost. It requests that it is resent.

•  TCP/IP becomes allows Inter network connections. So in 1977:

Page 13: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens
Page 14: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

The ARPAnet

•  1969 the birth of the ARPAnet.

•  1971 E-mail @

•  1977 the ARPAnet becomes a Inter-network.

•  1978 first Spam message send. Admin assures users this will never happen

again

Page 15: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

The Internet

•  1982 :-)

•  1983 TCP/IP becomes standard.

•  By 1990 most of Europe, India and South Africa have joined.

Page 16: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens
Page 17: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

Domain Name Servers (DNS)

•  Remembering IP address is to hard.

•  So people associate names with addresses. e.g. news.bbc.com → 212.58.226.141

•  A hierarchy of servers list handle requests

•  The route for most of Europe is RIPE based in Amsterdam.

Page 18: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

The Internet

•  1988 The Morris Worm, CERT formed.

•  1989 The Web: HTTP and HTML.

•  1992 The first ISPs and Mosaic the first web browser.

•  1994 Yahoo

Page 19: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens
Page 20: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens
Page 21: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens
Page 22: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

Today

•  All computers on the Internet have an IP address.

•  Key Internet Protocols: TCP/IP

•  DNS to turn names into numbers.

Page 23: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

The Internet Protocol Stack

Application

Transport

Network

Link/Hardware

Internet communication uses a stack of protocols.

Each protocol uses the protocol below it to sent data.

Page 24: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

Using the Stack to Send Data

Application

Transport

Network

Link/Hardware

Application

Transport

Network

Link/Hardware

Data

HT(Data)

HN(HT(Da) HN(HT(ta))

HLHN(HT(Da), HLHN(HT(ta))

Computer 2 Computer 1

HN(HT(Da)

Data

HT(Data)

HLHN(HT(Da) ), HLHN(HT(ta))

HLHN(HT(ta))

Page 25: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

The Stack, Most of the Time:

Stuff that you write

TCP or UDP

IP

Ethernet or 802.11

Application

Transport

Network

Link/Hardware

Page 26: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

Sockets

•  A computer is Identified by an IP address. •  To allow multiple connections each

computer has a port number. •  WWW runs on port 80, ssh on port 22, dns

on 53, (free wifi). •  A simple connection between two

computers is called a socket. •  Sockets are uniquely identified by (IP sender, port sender,IP receiver,port receiver).

Page 27: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

Our View of the Stack in Java

Application Java Program

Sockets

Page 28: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

Sockets in Java

•  Use java.io.Socket to make a socket that connects to a remote computer.

•  Use java.io.ServerSocket to make a socket that listens for an incoming connection.

•  Sockets just give bytes, so then need a wrapper.

Page 29: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

Sending an Object

•  Java lets you send an object over a socket.

•  The Object must be Serializable and have a UID (see demo).

•  Use the ObjectStream wrapper to send Objects.

Page 30: The Internet and Java Sockets · Sockets in Java • Use java.io.Socket to make a socket that connects to a remote computer. • Use java.io.ServerSocket to make a socket that listens

Conclusion

•  The Internet uses a packet based routing system IP.

•  Sockets are an easy way to connect between machines.

•  Use the Socket and ServerSocket Class.

•  Use a wrapper for the socket for different data types.


Recommended