1 CPSC 826 Internetworking Client/Server Computing & Socket Programming Michele Weigle Department of Computer Science Clemson University [email protected]September 1, 2004 http://www.cs.clemson.edu/~mweigle/courses/cpsc826 2 Application-Layer Protocols Overview Application-layer protocols define: » The types of messages exchanged » The syntax and semantics of messages » The rules for when and how messages are sent Public protocols (defined in RFCs) » HTTP, FTP, SMTP, POP, IMAP, DNS Proprietary protocols » RealAudio, RealVideo » IP telephony » … local ISP company network regional ISP transport network link physical application Network Working Group R. Fielding UC Irvine Request for Comments: 2616 J. Gettys Compaq/W3C Obsoletes: 2068 J. Mogul Compaq Category: Standards Track H. Frystyk W3C/MIT L. Masinter Xerox June 1999 P. Leach Microsoft T. Berners-Lee W3C/MIT Hypertext Transfer Protocol -- HTTP/1.1 Abstract The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. It is a generic, stateless, protocol which can be used for many tasks beyond its use for hypertext, such as name servers and distributed object management systems, through extension of its request methods, error codes and headers [47]. A feature of HTTP is the typing and negotiation of data representation, allowing systems to be built independently of the data being transferred. HTTP has been in use by the World-Wide Web global information initiative since 1990. This specification defines the protocol referred to as "HTTP/1.1", and is an update to RFC 2068 [33]. 4 Application-Layer Protocols Outline The architecture of distributed systems » Client/Server computing » P2P computing » Hybrid (Client/Server and P2P) systems The programming model used in constructing distributed systems » Socket programming Example client/server systems and their application-level protocols » The World-Wide Web (HTTP) » Reliable file transfer (FTP) » E-mail (SMTP & POP) » Internet Domain Name System (DNS) local ISP company network regional ISP transport network link physical application
8
Embed
Client/Server Computing & Socket Programming · Client-Server Architecture Server: »always-on host »permanent IP address »server farms for scaling Clients: »communicate with server
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Application-layer protocols define:» The types of messages exchanged» The syntax and semantics of
messages» The rules for when and how
messages are sent
Public protocols (defined in RFCs)» HTTP, FTP, SMTP, POP, IMAP,
DNS
Proprietary protocols» RealAudio, RealVideo» IP telephony» …
local ISP
companynetwork
regional ISP
applicationtransportnetwork
linkphysical
application
3
Network Working Group R. Fielding UC IrvineRequest for Comments: 2616 J. Gettys Compaq/W3CObsoletes: 2068 J. Mogul CompaqCategory: Standards Track H. FrystykW3C/MIT L. Masinter XeroxJune 1999 P. LeachMicrosoft T. Berners-Lee W3C/MIT
Hypertext Transfer Protocol -- HTTP/1.1
Abstract
The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. It is a generic, stateless, protocol which can be used for many tasks beyond its use for hypertext, such as name servers and distributed object management systems, through extension of its request methods, error codes and headers [47]. A feature of HTTP is the typing and negotiation of data representation, allowing systems to be built independently of the data being transferred.
HTTP has been in use by the World-Wide Web global information initiative since 1990. This specification defines the protocol referred to as "HTTP/1.1", and is an update to RFC 2068 [33].
4
Application-Layer ProtocolsOutline
The architecture of distributed systems» Client/Server computing» P2P computing» Hybrid (Client/Server and P2P) systems
The programming model used inconstructing distributed systems» Socket programming
Example client/server systems andtheir application-level protocols» The World-Wide Web (HTTP)» Reliable file transfer (FTP)» E-mail (SMTP & POP)» Internet Domain Name System (DNS)
local ISP
companynetwork
regional ISP
applicationtransportnetwork
linkphysical
application
5
Application-Layer ProtocolsOutline
local ISP
companynetwork
regional ISP
applicationtransportnetwork
linkphysical
application
Protocol design issues:» In-band v. out-of-band control signaling» Push v. pull protocols» Persistent v. non-persistent connections
Client/server service architectures» Contacted server responds versus forwards
request
Example client/server systems andtheir application-level protocols» The World-Wide Web (HTTP)» Reliable file transfer (FTP)» E-mail (SMTP & POP)» Internet Domain Name System (DNS)
6
Application-Layer ProtocolsOutline
local ISP
companynetwork
regional ISP
applicationtransportnetwork
linkphysical
application
Example P2P systems andtheir application-level protocols» Gnutella» Napster (hybrid)» KaZaA
Typical network application hastwo pieces: client and server
Client:» Initiates contact with server
(“speaks first”)» Requests service from server» For Web, client is implemented in
browser; for e-mail, in mail reader
Server:» Provides requested service to client» “Always” running» May also include a “client interface”
applicationtransportnetwork
linkphysical
application
applicationtransportnetwork
linkphysical
application
reply
request
Client
Server
15
Client/Server ParadigmSocket programming
Sockets are the fundamentalbuilding block forclient/server systems
Sockets are created andmanaged by applications» Strong analogies with files
a host-local, applicationcreated/released, OS-controlledinterface into which anapplication process can bothsend and receive messagesto/from another (remote or local)application process
socket
Two types of transport servicesare available via the socket API:» UDP sockets: unreliable, datagram-oriented communications» TCP sockets: reliable, stream-oriented communications
16
Client/Server ParadigmSocket-programming using TCP
A socket is an application created, OS-controlledinterface into which an application can both sendand receive messages to and from anotherapplication» A “door” between application processes and end-to-end
transport protocols
process
TCP withbuffers,
variables
socket
controlled byapplicationdeveloper
controlled byoperating
system
Host (end system)
process
TCP withbuffers,
variables
socket
controlled byapplicationdeveloper
controlled byoperatingsystem
Host (end system)
Internet
17
Socket-programming using TCPTCP socket programming model
A TCP socket provides a reliable bi-directionalcommunications channel from one process to another» A “pair of pipes” abstraction
Process
socket
Host(end system)
Host (end system)
Internet Process
socketbytesbytes
write readwriteread
18
TCP withbuffers,
variables
TCP withbuffers,
variables
Socket-programming using TCPNetwork addressing for sockets
process
socket
End System End System
process
socketLocal port numbers(e.g., 6500)
Internet domainname of host
e.g., access.cs.clemson.eduDNS
Sockets are addressed using an IP address and portnumber
Internet addresses of hosts(e.g., 130.127.48.4)
19
Socket-programming using TCPSocket programming in Java
When the client creates a socket,the client’s TCP establishesconnection to server’s TCP
When contacted by a client,server creates a new socket forserver process to communicatewith client» This allows the server to talk with
multiple clients
Client creates a local TCPsocket specifying the host andport number of server process» Java resolves host names to IP
addresses using DNS Client contacts server
» Server process must be running» Server must have created socket
that “welcomes” client’s contact
Client
socket
Internet Server
socketbytes
bytes
write readwriteread
20
Socket-programming using TCPSocket creation in the client-server model
process
host orserver Internet
process
bytes
TCP 3-way handshake
ClientServer
3-way
handshake Client
clientsocket socket
“welcoming”socketsocket
connectionsocketsocket
bytes
socket
21
Socket-programming using TCPSimple client-server example
The client reads a line of text from standard input andsends the text to the server via a socket
The server receives the line of text from the client andconverts the line of characters to all uppercase
The server sends the converted line back to the client The client receives the converted text and writes it to
standard output
Serverwelcomingsocketsocket
connectionsocketsocket
Client
clientsocket socket
stdin
stdout
22
Socket programming with TCP ExampleClient structure
Client reads from standard input(inFromUser stream), writes toserver via a socket (outToServerstream)
Server reads line from a socket Server converts line to uppercase and
writes back to client Client reads from socket,
(inFromServer stream) printsmodified line to standard output
client socket
inFromServer
outToServer
inFromUser
Client Process
(1)
(2) (3)
Standardoutput
(4)
Standardinput
23
Socket programming with TCP ExampleClient/server TCP socket interaction in Java
create socket for incomingrequest (port=6789)
welcomeSocket = new ServerSocket(...)
wait for incomingconnection requestconnectionSocket = welcomeSocket.accept()
create socket,connect to torpedo1.cs.clemson.edu,port=6789clientSocket = new Socket(...)
closeconnectionSocket close
clientSocket
Server (running on torpedo1.cs.clemson.edu)
Client (running on shadow1.cs...)
read reply fromclientSocket
write request usingclientSocket
read request fromconnectionSocket
write reply toconnectionSocket
TCP connection setup
program flow
data flow
24
Socket programming with TCP ExampleJava client
import java.io.*; import java.net.*; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence;
BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in));
System.out.println("Client ready for input");
Socket clientSocket = new Socket("torpedo1.cs.clemson.edu", 6789);
// Create (buffered) input stream using standard input
// Create client socket with connection to server at port 6789
25
Socket programming with TCP ExampleJava client II
DataOutputStream outToServer = new DataOutputStream( clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader( new InputStreamReader( clientSocket.getInputStream()));