part 1 network computing

114
Network programming Network programming Lesson 1 Lesson 1 HUYNH Cong Phap, PhD [email protected] , hcphap@dut.udn.vn

Upload: linh-nguyen

Post on 19-Jun-2015

159 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Part 1 network computing

Network programmingNetwork programming

Lesson 1 Lesson 1

HUYNH Cong Phap, [email protected], [email protected]

Page 2: Part 1 network computing

Client – Server Computing

Page 3: Part 1 network computing

Client Server Architecture A network

architecture in which each computer or process on the network is either a client or a server.

Page 4: Part 1 network computing

Components Clients Servers Communication Networks

Client

Server

Page 5: Part 1 network computing

Applications that run on computers Rely on servers for

◦Files◦Devices◦Processing power

Example: E-mail client◦An application that enables you to send

and receive e-mail

Clients

Clients are Applications

Page 6: Part 1 network computing

Servers Computers or processes that

manage network resources◦Disk drives (file servers)◦Printers (print servers) ◦Network traffic (network servers)

Example: Database Server◦A computer system that processes

database queries

Servers Manage Resources

Page 7: Part 1 network computing

Communication Networks

Networks Connect Clients and

Servers

Page 8: Part 1 network computing

Client–Server Computing Process takes place

◦ on the server and◦ on the client

Servers ◦ Store and protect data ◦ Process requests from clients

Clients ◦ Make requests◦ Format data on the desktop

Client-Server Computing Optimizes Computing Resources

Page 9: Part 1 network computing

Application Functions Software application

functions are separated into three distinct parts

Client: Presentation & Application Logic

Server:Data Management

Page 10: Part 1 network computing

Application Components

Data Management

Application Logic

Presentation

3 Logical Tiers

1

2

3

Database Applications:Most common use of client-server architectures

ThinClient

FatClient

2 Client Types

Page 11: Part 1 network computing

Middleware Software that connects two

otherwise separate applications

Example: Middleware product linking a database system to a Web server

Client: Requests Data via Web

Database Server:Manages Data

Web Server:Presents Dynamic Pages

Middleware Links Applications

Page 12: Part 1 network computing

Types of Servers

Application Servers Audio/Video Servers Chat Servers Fax Servers FTP Servers Groupware Servers IRC Servers

List Servers Mail Servers News Servers Proxy Servers Telnet Servers Web Servers Z39.50 Servers

Source: http://webopedia.lycos.com

From A to Z

Page 13: Part 1 network computing

ADVANTAGES OF CLIENT-SERVER Advantages often cited include:

◦Centralization - access, resources, and data security are controlled through the server

◦Scalability - any element can be upgraded when needed

◦Flexibility - new technology can be easily integrated into the system

◦Interoperability - all components (clients, network, servers) work together

Page 14: Part 1 network computing

DISADVANTAGES OF CLIENT-SERVER Disadvantages often cited include:

◦Dependability - when the server goes down, operations cease

◦Higher than anticipated costs◦Can cause network congestion

Page 15: Part 1 network computing

CLIENT-SERVER ARCHITECTURES There are basically two types of

client-server architectures◦Two tier architectures◦Three tier architectures

The choice between the two should be made based on combination of:◦Schedule for project implementation◦Expected system changes and

enhancements

Page 16: Part 1 network computing

TWO-TIER ARCHITECTURES Application components

are distributed between the server and client software

In addition to part of the application software, the server also stores the data, and all data accesses are through the server.

The presentation (to the user) is handled strictly by the client software.

Server

Network

PC PC PC

Clients

Page 17: Part 1 network computing

TWO-TIER ARCHITECTURES (cont.) The PC clients assume the bulk of

the responsibility for the application logic.

The server assumes the bulk of the responsibility for data integrity checks, query capabilities, data extraction and most of the data intensive tasks, including sending the appropriate data to the appropriate clients.

Page 18: Part 1 network computing

TWO-TIER ARCHITECTURES, ADVANTAGES The commonly cited advantages of

two-tier systems include:◦Fast application development time◦Available tools are robust and lend

themselves to fast prototyping to insure user needs a met accurately and completely.

◦Conducive to environments with homogeneous clients, homogeneous applications, and static business rules.

Page 19: Part 1 network computing

TWO-TIER ARCHITECTURES, DISADVANTAGES The commonly cited disadvantages of

two-tier systems include:◦Not suitable for dispersed, heterogeneous

environments with rapidly changing business rules.

◦Because the bulk of the application logic is on the client, there is the problem of client software version control and new version redistribution.

◦Security can be complicated because a user may require separate passwords for each SQL server accessed.

Page 20: Part 1 network computing

THREE-TIER ARCHITECTURES

3-tier architectures attempt to overcome some of the limitations of the 2-tier architecture by separating presentation, processing, and data into 3 separate and distinct entities.

The software in the client handles the presentation (to the user) using similar tools as in the 2-tier architecture.

Server

Network

PC PC PC

Clients

Server

Page 21: Part 1 network computing

THREE-TIER ARCHITECTURES (cont.) When data or processing are

required by the presentation client, a call is made to the middle-tier functionality server.

This tier performs calculations, does reports, and makes any needed client calls to other servers (e.g.. a data base server).

Page 22: Part 1 network computing

THREE-TIER ARCHITECTURES (cont.) Middle tier servers are usually coded

in a highly portable, non-proprietary language such as C or C++.

Middle tier servers may be multithreaded and can be accessed by multiple clients.

The calling mechanism from client to server and from server to server is by means of RPC’s.

Page 23: Part 1 network computing

THREE-TIER ARCHITECTURES, ADVANTAGES (cont.) Commonly cited advantages

include:◦Having separate functionality servers

allows for the parallel development of individual tiers by application specialists.

◦Provides for more flexible resource allocation. Can reduce network traffic by having the functionality servers strip data to the precise structure needed before sending it to the clients.

Page 24: Part 1 network computing

THREE-TIER ARCHITECTURES, DISADVANTAGES Often cited disadvantages of 3-tier

architectures include:◦Creates an increased need for network

traffic management, server load balancing, and fault tolerance.

◦Current tools are relatively immature and are more complex.

◦Maintenance tools are currently inadequate for maintaining server libraries. This is a potential obstacle for simplifying maintenance and promoting code reuse throughout the organization.

Page 25: Part 1 network computing

Peer to Peer Computing

Page 26: Part 1 network computing

What is Peer-to-Peer? A model of communication where

every node in the network acts alike.

As opposed to the Client-Server model, where one node provides services and other nodes use the services.

Page 27: Part 1 network computing

Advantages of P2P Computing No central point of failure

◦ E.g., the Internet and the Web do not have a central point of failure.

◦ Most internet and web services use the client-server model (e.g. HTTP), so a specific service does have a central point of failure.

Scalability◦ Since every peer is alike, it is possible to add

more peers to the system and scale to larger networks.

Page 28: Part 1 network computing

Disadvantages of P2P Computing Decentralized coordination

◦How to keep global state consistent?◦Need for distributed coherency

protocols. All nodes are not created equal.

◦Computing power, bandwidth have an impact on overall performance.

Programmability◦As a corollary of decentralized

coordination.

Page 29: Part 1 network computing

P2P Computing Applications

File sharing

Process sharing

Collaborative environments

Page 30: Part 1 network computing

P2P File Sharing Applications Improves data availability Replication to compensate for

failures. E.g., Napster, Gnutella, Freenet,

KaZaA (FastTrack), your DFS project.

Page 31: Part 1 network computing

P2P Process Sharing Applications

For large-scale computations Data analysis, data mining,

scientific computing E.g., SETI@Home, Folding@Home,

distributed.net, World-Wide Computer

Page 32: Part 1 network computing

P2P Collaborative Applications

For remote real-time human collaboration.

Instant messaging, virtual meetings, shared whiteboards, teleconferencing, tele-presence.

E.g., talk, IRC, ICQ, AOL Messenger, Yahoo! Messenger, Jabber, MS Netmeeting, NCSA Habanero, Games

Page 33: Part 1 network computing

Types of P2P Pure P2P

Hybrid P2P

Page 34: Part 1 network computing

Napster

Page 35: Part 1 network computing

Gnutella

But introduces a new single point of failure!But introduces a new single point of failure!

Page 36: Part 1 network computing

KaZaA/Morpheus

Page 37: Part 1 network computing

Distributed systemsData Networking &

Client-Server Communication

Page 38: Part 1 network computing

Distributed systems

Independent machines work cooperatively without shared memory

They have to talk somehow

Interconnect is the network

Page 39: Part 1 network computing

Modes of connection

Circuit-switched◦ dedicated path◦ guaranteed (fixed) bandwidth◦ [almost] constant latency

Packet-switched◦ shared connection◦ data is broken into chunks called packets◦ each packet contains destination address◦ available bandwidth channel capacity◦ variable latency

Page 40: Part 1 network computing

What’s in the data? For effective communication

◦ same language, same conventions For computers:

◦ electrical encoding of data◦ where is the start of the packet?◦ which bits contain the length?◦ is there a checksum? where is it?

how is it computed?◦ what is the format of an address?◦ byte ordering

Page 41: Part 1 network computing

Protocols

These instructions and conventionsare known as protocols

Page 42: Part 1 network computing

Protocols

Exist at different levelsunderstand format of address and how to compute checksum

request web page

humans vs. whalesdifferent wavelengths

French vs. Hungarian

versus

Page 43: Part 1 network computing

Layering To ease software development and maximize flexibility:

◦ Network protocols are generally organized in layers

◦ Replace one layer without replacing surrounding layers

◦ Higher-level software does not have to know how to format an Ethernet packet … or even know that Ethernet is

being used

Page 44: Part 1 network computing

Layering

Most popular model of guiding(not specifying) protocol layers is

OSI reference model

Adopted and created by ISO

7 layers of protocols

Page 45: Part 1 network computing

OSI Reference Model: Layer 1

Transmits and receives raw data to communication medium.

Does not care about contents.

voltage levels, speed, connectors

PhysicalPhysical1Examples: RS-232, 10BaseT

Page 46: Part 1 network computing

Data LinkData Link

OSI Reference Model: Layer 2

Detects and corrects errors.

Organizes data into packets before passing it down. Sequences packets (if necessary).

Accepts acknowledgements from receiver.

PhysicalPhysical1

2

Examples: Ethernet MAC, PPP

Page 47: Part 1 network computing

NetworkNetwork

Data LinkData Link

OSI Reference Model: Layer 3

Relay and route information to destination.

Manage journey of packets and figure out intermediate hops (if needed).

PhysicalPhysical1

2

3

Examples: IP, X.25

Page 48: Part 1 network computing

TransportTransport

NetworkNetwork

Data LinkData Link

OSI Reference Model: Layer 4

Provides a consistent interface for end-to-end (application-to-application) communication. Manages flow control.

Network interface is similar to a mailbox.

PhysicalPhysical1

2

3

4

Examples: TCP, UDP

Page 49: Part 1 network computing

SessionSession

TransportTransport

NetworkNetwork

Data LinkData Link

OSI Reference Model: Layer 5

Services to coordinate dialogue and manage data exchange.

Software implemented switch.

Manage multiple logical connections.

Keep track of who is talking: establish & end communications.

PhysicalPhysical1

2

3

4

5

Examples: HTTP 1.1, SSL, NetBIOS

Page 50: Part 1 network computing

PresentationPresentation

SessionSession

TransportTransport

NetworkNetwork

Data LinkData Link

OSI Reference Model: Layer 6

Data representation

Concerned with the meaning of data bits

Convert between machine representations

PhysicalPhysical1

2

3

4

5

6

Examples: XDR, ASN.1, MIME, MIDI

Page 51: Part 1 network computing

ApplicationApplication

PresentationPresentation

SessionSession

TransportTransport

NetworkNetwork

Data LinkData Link

OSI Reference Model: Layer 7

Collection of application-specific protocols

PhysicalPhysical1

2

3

4

5

6

7

Examples: email (SMTP, POP, IMAP) file transfer (FTP) directory services (LDAP)

Page 52: Part 1 network computing

Some networking terminology

Page 53: Part 1 network computing

Local Area Network (LAN)Communications network

◦ small area (building, set of buildings)◦ same, sometimes shared, transmission

medium◦ high data rate (often): 1 Mbps – 1 Gbps◦ Low latency◦ devices are peers

any device can initiate a data transfer with any other device

Most elements on a LAN are workstations◦ endpoints on a LAN are called nodes

Page 54: Part 1 network computing

Connecting nodes to LANs

?

network computer

Page 55: Part 1 network computing

Connecting nodes to LANsnetwork computer

Adapter◦ expansion slot (PCI, PC Card, USB dongle)◦ usually integrated onto main board

Network adapters are referred to asNetwork Interface Cards (NICs) or adapters

or Network Interface Component

Page 56: Part 1 network computing

MediaWires (or RF, IR) connecting together the devices that make up a LAN

Twisted pair◦ Most common:

STP: shielded twisted pair UTP: unshielded twisted pair

(e.g. Telephone cable, Ethernet 10BaseT)

Coaxial cable◦ Thin (similar to TV cable)◦ Thick (e.g., 10Base5, ThickNet)

FiberWireless

Page 57: Part 1 network computing

Hubs, routers, bridgesHub

◦ Device that acts as a central point for LAN cables◦ Take incoming data from one port & send to all other ports

Switch◦ Moves data from input to output port.◦ Analyzes packet to determine destination port and makes

a virtual connection between the ports.Concentrator or repeater

◦ Regenerates data passing through itBridge

◦ Connects two LANs or two segments of a LAN◦ Connection at data link layer (layer 2)

Router◦ Determines the next network point to which a packet

should be forwarded◦ Connects different types of local and wide area networks

at network layer (layer 3)

Page 58: Part 1 network computing

Networking Topology

Bus Network

Page 59: Part 1 network computing

Networking Topology

Tree Network

Page 60: Part 1 network computing

Networking Topology

Star Network

Page 61: Part 1 network computing

Networking Topology

Ring Network

Page 62: Part 1 network computing

Networking Topology

Mesh Network

Page 63: Part 1 network computing

Clients and Servers

Send messages to applications◦ not just machines

Client must get data to the desired process◦ server process must get data back to client

process

To offer a service, a server must get a transport address for a particular service◦ well-defined location

Page 64: Part 1 network computing

Machine address

versus

Transport address

Page 65: Part 1 network computing

Transport provider

Layer of software that accepts a network message and sends it to a remote machine

Two categories:connection-oriented protocols

connectionless protocols

Page 66: Part 1 network computing

Connection-oriented Protocols

1. establish connection2. [negotiate protocol]3. exchange data4. terminate connection

Page 67: Part 1 network computing

Connection-oriented Protocols

virtual circuit service◦ provides illusion of having a dedicated

circuit◦ messages guaranteed to arrive in-order◦ application does not have to address

each messagevs. circuit-switched service

1. establish connection2. [negotiate protocol]3. exchange data4. terminate connection

dial phone number[decide on a language]speakhang up

analogous to phone call

Page 68: Part 1 network computing

Connectionless Protocols

- no call setup- send/receive data

(each packet addressed)- no termination

Page 69: Part 1 network computing

Connectionless Protocols

datagram service◦ client is not positive whether message

arrived at destination◦ no state has to be maintained at client or

server◦ cheaper but less reliable than virtual circuit

service

- no call setup- send/receive data

(each packet addressed)- no termination

drop letter in mailbox(each letter addressed)

analogous to mailbox

Page 70: Part 1 network computing

Ethernet

Layers 1 & 2 of OSI model◦ Physical (1)

Cables: 10Base-T, 100Base-T, 1000Base-T, etc.

◦ Data Link (2) Ethernet bridging Data frame parsing Data frame transmission Error detection

Unreliable, connectionless communication

Page 71: Part 1 network computing

Ethernet

48-byte ethernet address Variable-length packet

◦ 1518-byte MTU 18-byte header, 1500 bytes data

Jumbo packets for Gigabit ethernet◦ 9000-byte MTU

dest addr src addrframe type

6 bytes 6 bytes 2

data (payload) CRC

446-1500 bytes

18 bytes + data

Page 72: Part 1 network computing

IP – Internet Protocol

Born in 1969 as a research network of 4 machinesFunded by DoD’s ARPA

Goal:

build an efficient fault-tolerant network that could connect heterogeneous machines and link separately connected networks.

Page 73: Part 1 network computing

Internet Protocol

Connectionless protocol designed to handle the interconnection of a large number of local and wide-area networks that comprise the internet

IP can route from one physical network to another

Page 74: Part 1 network computing

IP Addressing

Each machine on an IP network is assigned a unique 32-bit number for each network interface:

◦ IP address, not machine address

A machine connected to several physical networks will have several IP addresses

◦ One for each network

Page 75: Part 1 network computing

IP Address space

32-bit addresses >4 billion addresses!

Routers would need a table of 4 billion entries

Design routing tables so one entry can match multiple addresses◦ hierarchy: addresses physically close will

share a common prefix

Page 76: Part 1 network computing

IP Addressing: networks & hosts

first 16 bits identify Rutgers external routers need only one entry

◦ route 128.6.*.* to Rutgers

cs.rutgers.edu128.6.4.2

80 06 04 02

remus.rutgers.edu128.6.13.3

80 06 0D 03

network # host #

Page 77: Part 1 network computing

IP Addressing: networks & hosts IP address

◦ network #: identifies network machine belongs to

◦ host #: identifies host on the network

use network number to route packet to correct network

use host number to identify specific machine

Page 78: Part 1 network computing

IP Addressing

Expectation:◦ a few big networks and many small ones◦ create different classes of networks◦ use leading bits to identify network

To allow additional networks within an organization:

use high bits of host number for a“network within a network” – subnet

class leading bits

bits for net #

bits for host

A 0 7 (128) 24 (16M)

B 10 14 (16K) 16 (64K)

C 110 21 (2M) 8 (256)

Page 79: Part 1 network computing

IP Addressing

IBM: 9.0.0.0 – 9.255.255.255

00001001 xxxxxxxx xxxxxxxx xxxxxxxxx

network #8 bits

host #24 bits

00001001 10101010 11 xxxxxx xxxxxxxxx

network #18 bits

host #14 bits

Subnet within IBM (internal routers only)

Page 80: Part 1 network computing

Running out of addresses Huge growth

Wasteful allocation of networks◦ Lots of unused addresses

Every machine connected to the internet needed a worldwide-unique IP address

Solutions: CIDR, NAT, IPv6

Page 81: Part 1 network computing

IP Special Addresses All bits 0

◦ Valid only as source address◦ “all addresses for this machine”◦ Not valid over network

All host bits 1◦ Valid only as destination◦ Broadcast to network

All bits 1◦ Broadcast to all directly connected networks

Leading bits 1110◦ Class D network

127.0.0.0: reserved for local traffic◦ 127.0.0.1 usually assigned to loopback device

Page 82: Part 1 network computing

IPv6 vs. IPv4

IPv4◦ 4 byte (32 bit) addresses

IPv6:◦ 16-byte (128 bit) addresses

3.6 x 1038 possible addresses8 x 1028 times more addresses than IPv4

◦ 4-bit priority field◦ Flow label (24-bits)

Page 83: Part 1 network computing

Network Address Translation (NAT)

External IP address24.225.217.243

InternalIP address

192.168.1.x .1 .2 .3 .4 .5

Page 84: Part 1 network computing

Getting to the machine

IP is a logical network on top of multiple physical networks OS support for IP: IP driver

IP driverIP driver

network drivernetwork driver

send data

send packet

to wirefrom wire

receive packet

receive data

Page 85: Part 1 network computing

IP driver responsibilities Get operating parameters from device

driver◦ Maximum packet size (MTU)◦ Functions to initialize HW headers◦ Length of HW header

Routing packets◦ From one physical network to another

Fragmenting packets Send operations from higher-layers Receiving data from device driver Dropping bad/expired data

Page 86: Part 1 network computing

Device driver responsibilities Controls network interface card

◦ Comparable to character driver

Processes interrupts from network interface◦ Receive packets◦ Send them to IP driver

Get packets from IP driver◦ Send them to hardware◦ Ensure packet goes out without collision

bott

om

half

top h

alf

Page 87: Part 1 network computing

Network device

Network card examines packets on wire◦ Compares destination addresses

Before packet is sent, it must be enveloped for the physical networkdeviceheader

payload

IP header IP data

Page 88: Part 1 network computing

Device addressing

IP address ethernet address

Address Resolution Protocol (ARP)1. Check local ARP cache2. Send broadcast message requesting

ethernet address of machine with certain IP address

3. Wait for response (with timeout)

Page 89: Part 1 network computing

Transport-layer protocols over IP IP sends packets to machine

◦ No mechanism for identifying sending or receiving application

Transport layer uses a port number to identify the application

TCP – Transmission Control Protocol UDP – User Datagram Protocol

Page 90: Part 1 network computing

TCP – Transmission Control Protocol Virtual circuit service

(connection-oriented) Send acknowledgement for each

received packet Checksum to validate data Data may be transmitted

simultaneously in both directions

Page 91: Part 1 network computing

UDP – User Datagram Protocol Datagram service (connectionless) Data may be lost Data may arrive out of sequence Checksum for data but no

retransmission◦ Bad packets dropped

Page 92: Part 1 network computing

IP headerdeviceheader

payload

IP header IP dataTCP/UDPheader

total length

options and pad

svc type (TOS)vers hlen

fragment identification flags fragment offset

TTL protocol header checksum

source IP address

destination IP address

20

byte

s

Page 93: Part 1 network computing

Headers: TCP & UDPdeviceheader

IP header IP dataTCP/UDPheader

src port dest port

seq number

ack number

hdrlen

flags

checksum urgent ptr

options and pad

- window

src port dest port

seg length checksum

TCP header UDP header

20 b

yte

s

8 bytes

payload

Page 94: Part 1 network computing

Device header (Ethernet II)deviceheader

IP header IP dataTCP/UDPheader

dest addr src addrframe type

6 bytes 6 bytes 2

data CRC

446-1500 bytes

18 bytes + data

payload

Page 95: Part 1 network computing

Quality of Service Problems in IP Too much traffic

◦ Congestion

Inefficient packet transmission◦ 59 bytes to send 1 byte in TCP/IP!◦ 20 bytes TCP + 20 bytes IP + 18 bytes

ethernet

Unreliable delivery◦ Software to the rescue – TCP/IP

Unpredictable packet delivery

Page 96: Part 1 network computing

Programming Interfaces

Page 97: Part 1 network computing

Sockets IP lets us send data between machines

TCP & UDP are transport layer protocols◦ Contain port number to identify transport

endpoint (application)

One popular abstraction for transport layer connectivity: sockets◦ Developed at Berkeley

Page 98: Part 1 network computing

Sockets

Attempt at generalized IPC modelGoals:

◦ communication between processes should not depend on whether they are on the same machine

◦ efficiency◦ compatibility◦ support different protocols and

naming conventions

Page 99: Part 1 network computing

Socket

Abstract object from which messages are sent and received

◦ Looks like a file descriptor◦ Application can select particular style of

communication Virtual circuit, datagram, message-based, in-

order delivery

◦ Unrelated processes should be able to locate communication endpoints Sockets should be named Name meaningful in the communications

domain

Page 100: Part 1 network computing

Programming with sockets

Page 101: Part 1 network computing

Step 1

Create a socketint s = socket(domain, type, protocol)

AF_INET SOCK_STREAMSOCK_DGRAM

useful if some families have more than one protocol to support a given service

Page 102: Part 1 network computing

Step 2

Name the socket (assign address, port)int error = bind(s, addr, addrlen)

socket Address structure struct sockaddr*

length of address structure

Page 103: Part 1 network computing

Step 3a (server)Set socket to be able to accept connections

int error = listen(s, backlog)

socket queue length for pending connections

Page 104: Part 1 network computing

Step 3b (server)

Wait for a connection from clientint snew = accept(s, clntaddr, &clntalen)

socket pointer to address structure

length of address structurenew socket

for this session

Page 105: Part 1 network computing

Step 3 (client)

Connect to serverint error = connect(s, svraddr, svraddrlen)

socket Address structure struct sockaddr*

length of address structure

Page 106: Part 1 network computing

Step 4

Exchange data

Connection-orientedread/writerecv/send (extra flags)

Connectionlesssendto, sendmsgrecvfrom, recvmsg

Page 107: Part 1 network computing

Step 5

Close connection

shutdown(s, how)

how:0: can send but not receive1: cannot send more data2: cannot send or receive (=0+1)

Page 108: Part 1 network computing

Sockets in Java

java.net package

Two major classes:◦ Socket: client-side◦ ServerSocket: server-side

Page 109: Part 1 network computing

Step 1a (server)

Create socket and name it

ServerSocket svc =new ServerSocket(port)

Page 110: Part 1 network computing

Step 1b (server)

Wait for connection from client

Server req = svc.accept()

new socket for client session

Page 111: Part 1 network computing

Step 1 (client)

Create socket and name it

Socket s = new Socket(address, port);

obtained from:getLocalHost, getByName,or getAllByName

Socket s =new Socket(“cs.rutgers.edu”, 2211);

Page 112: Part 1 network computing

Step 2

Exchange dataobtain InputStream/OutputStream from Socket object

BufferedReader in = new BufferedReader(

new InputStreamReader(s.getInputStream()));

PrintStream out = new PrintStream(s.getOutputStream());

Page 113: Part 1 network computing

Step 3

Terminate connectionclose streams, close socket

in.close();out.close();s.close();

Page 114: Part 1 network computing

The end.