Docsity

Java Networking: OOP II in CMSC 132 at UMD, College Park, Study notes of Computer Science

Partial preview of the text

Download Java Networking: OOP II in CMSC 132 at UMD, College Park and more Study notes Computer Science in PDF only on Docsity!

CMSC 132:

Object-Oriented Programming II

Networking Support in Java

Department of Computer Science

University of Maryland, College Park

Overview

Networking

Background Concepts & terms Network applications Java’s objected-oriented view Java’s networking API

(Application Program Interface)

Last lecture

This lecture

Client / Server Model Examples

Application

Client

Server

Web Browsing

Internet Explorer,

Mozilla Firefox

Apache,

Microsoft IIS

Email

MS Outlook,Thunderbird

POP, IMAP,

Exchange

Streaming

Music

Windows Media

Player, iTunes

Internet Radio

Online Gaming

World of Warcraft,Halo 3, PartyPoker

Game / Realm

Servers

Client Programming

Basic steps

Determine server location – IP address & port

Open network connection to server

Write data to server (request)

Read data from server (response)

Close network connection

Stop client

Advanced Server Programming

Server supports multiple connections / clients Two approaches 1.

Loop

Handles multiple connections in order Limits on amount of network traffic Not resilient in face of slow / stopped clients

Multithreading

Allows multiple simultaneous connections

Networking in Java

Packages

java.net

Networking

java.io

I/O streams & utilities

java.rmi

Remote Method Invocation

java.security

Security policies

java.lang

Threading classes

Support at multiple levels

Data transport

Socket classes

Network services

URL classes

Utilities & security

Java Networking Classes

IP addresses

InetAddress

Packets

DatagramPacket

Sockets

Socket ServerSocket DatagramSocket

URLs

URL

InetAddress Class

Represents an IP address Can convert domain name to IP address

Performs DNS lookup

Getting an InetAddress object

getLocalHost( ) getByName(String host) getByAddress(byte[ ] addr)

DatagramPacket Class

Data in packet represented as byte array

DatagramPacket Methods

getAddress() getData() getLength() getPort() setAddress() setData() setLength() setPort()

Socket Class

Creates socket for client Constructor connects to

Machine name or IP address Port number

Transfer data via streams

Standard Java I/O streams

Bytes

InputStream, OutputStream

Characters

FileReader, PrintWriter

Socket Methods

getInputStream() getOutputStream() close() getInetAddress() getPort() getLocalPort()

ServerSocket Methods

accept() close() getInetAddress() getLocalPort()

Connection Oriented

TCP Protocol