5COSC022W Lecture Week02 Networking Socket Programming (3)
5COSC022W Lecture Week02 Networking Socket Programming (3)
2
The Internet: a “nuts and bolts” view
mobile network
4G
• Internet: “network of networks” national or global ISP
• Interconnected ISPs
▪ protocols are everywhere Skype
IP
Streaming
video
• control sending, receiving of
messages local or
regional ISP
• e.g., HTTP (Web), streaming video,
Skype, TCP, IP, WiFi, 4G, Ethernet home network content
provider
▪ Internet standards HTTP network datacenter
network
WiFi
3
What’s a protocol?
4
What’s a protocol?
A human protocol and a computer network protocol:
Hi TCP connection
request
Hi TCP connection
response
Got the
time? GET http://gaia.cs.umass.edu/kurose_ross
2:00
<file>
time
5
OSI Model
• OSI Model (Open Systems Interconnection Model) is a reference tool and a
reference model for data communications in networks”. Proposed by the
International Standards Organization (ISO).
6
TCP/IP model
TCP/IP Model
OSI Model
The original TCP/IP protocol suite was
defined as having four layers: host-to-
network, internet, transport, and
application.
7
Physical Address
Also known as a MAC (Media Access Control) address, it is a unique identifier
assigned to network interfaces for communication within a network.
Length: MAC addresses are 48 bits long and commonly expressed as six
groups of two hexadecimal digits.
8
Port Address
01 02 03
Ports are virtual Range: Ports are Types: Well-known
endpoints for identified by ports (0-1023),
communication in a numbers from 0 to registered ports
network. 65535. (1024-49151), and
dynamic or private
ports (49152-65535).
IP Class A
Most commonly used class for home and small business networks
IP Class D and E
10.0.0.0 to 10.255.255.255
Range: Examples include addresses 172.16.0.0 to 172.31.255.255
from the following ranges:
192.168.0.0 to 192.168.255.255
subnet 223.1.1/24
223.1.1.1
▪ where are the 223.1.1.4
subnets? 223.1.1.3
addresses?
223.1.9.1 223.1.7.1
223.1.8.1 223.1.8.0
• 255.255.255.0
Subnetting
IP addressing: CIDR
Subnetting
Example Expanded to three
departments: Development,
Scenario: Marketing, Sales.
Innovate Inc.
Facing network congestion,
security concerns, and IP
address exhaustion.
The Solution: Subnetting
• Divide the 192.168.1.0 network into four subnets.
• Use subnet mask 255.255.255.192 (or /26 in CIDR notation).
• One subnet for each department (Development, Marketing, Sales)
and one for shared resources.
Subnet Network Address Subnet Mask Usable IP Range Purpose
192.168.1.1 -
Subnet 1 192.168.1.0 255.255.255.192 Development
192.168.1.62
192.168.1.65 -
Subnet 2 192.168.1.64 255.255.255.192 Marketing
192.168.1.126
192.168.1.129 -
Subnet 3 192.168.1.128 255.255.255.192 Sales
192.168.1.190
192.168.1.193 -
Subnet 4 192.168.1.192 255.255.255.192 Shared Resources
192.168.1.254
Subnetting Calculation
Step 1 - Binary
• Convert Subnet Mask to Binary:
• 255.255.255.192 becomes 11111111.11111111.11111111.11000000
DHCP overview:
▪ host broadcasts DHCP discover msg [optional]
▪ DHCP server responds with DHCP offer msg [optional]
▪ host requests IP address: DHCP request msg
▪ DHCP server sends address: DHCP ack msg
NAT: network address translation
NAT: all devices in local network share just one IPv4 address as
far as outside world is concerned
rest of local network (e.g., home
Internet network) 10.0.0/24
10.0.0.1
138.76.29.7 10.0.0.4
10.0.0.2
10.0.0.3
all datagrams leaving local network have datagrams with source or destination in
same source NAT IP address: 138.76.29.7, this network have 10.0.0/24 address for
but different source port numbers source, destination (as usual)
ARP: address resolution protocol
Question: how to determine interface’s MAC address, knowing its IP
address?
ARP table: each IP node (host,
ARP
router) on LAN has table
137.196.7.78
ARP
1A-2F-BB-76-09-AD • IP/MAC address mappings for
ARP some LAN nodes:
LAN < IP address; MAC address; TTL>
71-65-F7-2B-08-53
137.196.7.23
58-23-D7-FA-20-B0
137.196.7.14 • TTL (Time To Live): time after
ARP 0C-C4-11-6F-E3-98 which address mapping will be
137.196.7.88
forgotten (typically 20 min)
30
ARP protocol in action
example: A wants to send datagram to B
• B’s MAC address not in A’s ARP table, so A uses ARP to find B’s MAC address
D
31
ARP protocol in action
Example: A wants to send datagram to B
• B’s MAC address not in A’s ARP table, so A uses ARP to find B’s MAC address
32
ARP protocol in action
example: A wants to send datagram to B
• B’s MAC address not in A’s ARP table, so A uses ARP to find B’s MAC address
C
ARP table in A
IP addr MAC addr TTL
TTL
137.196. 58-23-D7-FA-20-B0 500
A B
7.14
71-65-F7-2B-08-53 58-23-D7-FA-20-B0
137.196.7.23 137.196.7.14
33
TCP: overview
▪ point-to-point: ▪ cumulative ACKs
• one sender, one receiver ▪ pipelining:
▪ reliable, in-order byte steam: • TCP congestion and flow control
• no “message boundaries" set window size
▪ full duplex data: ▪ connection-oriented:
• bi-directional data flow in same • handshaking (exchange of control
connection messages) initializes sender,
• MSS: maximum segment size receiver state before data exchange
▪ flow controlled:
• sender will not overwhelm receiver
Transport Layer Actions
Sender:
application ▪ is passed an application- application
app. msg
layer message
transport ▪ determines segment TThhtransport
app. msg
header fields values
network (IP) ▪ creates segment network (IP)
physical physical
Transport Layer Actions
Receiver:
application ▪ receives segment from IP application
▪ checks header values
app. msg
transport ▪ extracts application-layer transport
message
network (IP)
network (IP) ▪ demultiplexes message up
link to application via socket link
physical physical
Th app. msg
Agreeing to establish a connection
2-way handshake:
choose x
req_conn(x)
ESTAB
acc_conn(x)
ESTAB
data(x+1) accept
data(x+1)
ACK(x+1)
connection
x completes
No problem!
choose x
req_conn(x)
ESTAB
retransmit acc_conn(x)
req_conn(x)
ESTAB
req_conn(x)
connection
client x completes server
terminates forgets x
ESTAB
acc_conn(x)
Problem: half open
connection! (no client)
Transport Layer: 3-39
2-way handshake scenarios
choose x
req_conn(x)
ESTAB
retransmit acc_conn(x)
req_conn(x)
ESTAB
data(x+1) accept
data(x+1)
retransmit
data(x+1)
connection
x completes server
client
terminates forgets x
req_conn(x)
ESTAB
data(x+1) accept
data(x+1)
Problem: dup data
accepted!
TCP 3-way handshake
Server state
serverSocket = socket(AF_INET,SOCK_STREAM)
Client state serverSocket.bind((‘’,serverPort))
serverSocket.listen(1)
clientSocket = socket(AF_INET, SOCK_STREAM) connectionSocket, addr = serverSocket.accept()
LISTEN
clientSocket.connect((serverName,serverPort)) LISTEN
choose init seq num, x
send TCP SYN msg
SYNSENT SYNbit=1, Seq=x
choose init seq num, y
send TCP SYNACK
msg, acking SYN SYN RCVD
SYNbit=1, Seq=y
ACKbit=1; ACKnum=x+1
received SYNACK(x)
ESTAB indicates server is live;
send ACK for SYNACK;
this segment may contain ACKbit=1, ACKnum=y+1
client-to-server data
received ACK(y)
indicates client is live
ESTAB
enterprise
network
UDP: User Datagram Protocol
Why is there a UDP?
▪ “no frills,” “bare bones”
Internet transport protocol ▪ no connection
establishment (which can
▪ “best effort” service, UDP add RTT delay)
segments may be: ▪ simple: no connection state
• lost at sender, receiver
• delivered out-of-order to app ▪ small header size
▪ connectionless: ▪ no congestion control
• no handshaking between UDP ▪ UDP can blast away as fast as
desired!
sender, receiver
▪ can function in the face of
• each UDP segment handled congestion
independently of others
UDP: User Datagram Protocol
▪ UDP use:
▪ streaming multimedia apps (loss tolerant, rate sensitive)
▪ DNS
▪ SNMP
▪ HTTP/3
▪ if reliable transfer needed over UDP (e.g., HTTP/3):
▪ add needed reliability at application layer
▪ add congestion control at application layer
Sockets
goal: learn how to build client/server applications that
communicate using sockets
socket: door between application process and end-end-transport
protocol
application application
socket controlled by
process process app developer
transport transport
network network controlled
link by OS
link Internet
physical physical
How do
sockets
work?
Client/server socket interaction: TCP
write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
Java
Networking
Packages
Java Socket
Socket Programming
reader.close();
writer.close();
clientSocket.close();
serverSocket.close();
Close
} catch (IOException e) { resources
e.printStackTrace();
}
}
}