Docsity

Networking - Object-Oriented Programming II - Notes | CMSC 132, Study notes of Computer Science

Partial preview of the text

Download Networking - Object-Oriented Programming II - Notes | CMSC 132 and more Study notes Computer Science in PDF only on Docsity!

CMSC 132:

Object-Oriented Programming II

Networking

Department of Computer Science

University of Maryland, College Park

Networking

Internet

Designed with multiple layers of abstraction Underlying medium is unreliable, packet oriented Provides two views Reliable, connection oriented (TCP) Unreliable, packet oriented (UDP)

Java

Object-oriented classes & API Sockets, URLs Extensive networking support

Internet (IP) Address

Problem

Running out of 32-bit IP addresses Caused by initial address allocation Stanford & MIT initially given more IP addresses than China fixed in 2000 Univ. of Maryland is currently assigned 131, IP addresses

Switching to 128-bit IP addresses in IPv

1+ million addresses per square meter on Earth

IP Address โ€“ DNS

Domain Name System (DNS)

Protocol for translating domain names to IP addresses Example: cs.umd.edu โ†’ 128.8.128. Multiple DNS servers on internet DNS server may need to query other DNS servers edu DNS server queries umd.edu server to find cs.umd.edu

Sockets

Application-level abstraction

Represents network connection Implemented in software Supports both UDP and TCP protocols

History

Introduced in Berkley UNIX in 1980s Networking API

Sockets

Socket is bound to port number

Receives data packet Relays to specific port port port port port port TCP or UDP port #, data Packet app app app app app Transport Layer

Uniform Resource Locators (URLs)

Consists of

Protocol http: https: (secure http) file: โ€ฆ IP address (or domain name) Port (optional, 80 if not specified) http://www.cs.umd.edu:80/ Reference to anchor (optional) Query terms

Internet Connections

Two types of connections

  1. Connection-oriented (TCP)
  2. Packet-oriented (UDP)

Transmission Control Protocol (TCP)

Reliable but more overhead for small messages

Application can treat as reliable connection

Despite unreliability of underlying IP (network)

Examples

ftp (file transfer) ssh (remote secure shell) http (web)

Vast majority of internet traffic is TCP

User Datagram Protocol (UDP)

More like sending a postcard

Limited size message

Might get lost with no notification

Useful is some specialized cases

messages are small if a packet is lost, would rather just lose it than delay receipt of next packet

Client / Server Model

Relationship between two computer programs

Client

Initiates communication Requests services

Server

Receives communication Provides services

Other models

Master / worker Peer-to-peer (P2P)

Client

Client

Client

Server

Server

Client

Client Programming

Basic steps

  1. Determine server location โ€“ IP address & port
  2. Open network connection to server
  3. Write data to server (request)
  4. Read data from server (response)
  5. Close network connection
  6. Stop client

Java Networking Classes IP addresses InetAddress Packets DatagramPacket Sockets Socket - TCP client sockets ServerSocket - TCP server sockets DatagramSocket - UDP sockets (server or client) Sockets transfer data via Java I/O streams URL Connection Classes High-level description of network service Access resource named by URL Examples URLConnection โ‡’ Reads resource HttpURLConnection โ‡’ Handles web page JarURLConnection โ‡’ Manipulates Java Archive

Java Networking Examples TCP Client/Server: See tcpServerClient package UDP Client/Server: See udpServerClient package URL Reader: See urlReader package Toy Web Server: See toyWebServer package