Client-Server Paradigm and Performance L. Grewe. 2 Review: Basic Client-Server Request/Reply Paradigm Typical Internet app has two pieces: client and.

Slides:



Advertisements
Similar presentations
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r Sockets are explicitly created, used, released by applications.
Advertisements

Network Programming and Java Sockets
Application Layer 2-1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Application Layer – Lecture.
2: Application Layer 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
9/23/2003-9/25/2003 Sockets & DNS September 23-25, 2003.
1 Creating a network app Write programs that  run on different end systems and  communicate over a network.  e.g., Web: Web server software communicates.
2: Application Layer1 Data Communication and Networks Lecture 12 Java Sockets November 30, 2006.
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
1 Review of Previous Lecture r Electronic Mail r DNS r P2P file sharing.
Internet and Intranet Protocols and Applications Lecture 4: Application Layer 3: Socket Programming February 8, 2005 Arthur Goldberg Computer Science Department.
2: Application Layer1 Chapter 2 (continued) Application Layer – part 2 Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim.
Lecture 11 Java Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Joonbok Lee.
Socket programming with UDP and TCP. Socket Programming with TCP Connection oriented – Handshaking procedure Reliable byte-stream.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
1 Network Layers Application Transport Network Data-Link Physical bits.
Protocols Rules for communicating between two entities (e.g., a client and a server) “A protocol definition specifies how distributed system elements interact.
Welcome to CIS 235 Computer Networks Fall, 2007 Prof Peterson.
2: Application Layer 1 Socket Programming Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley,
JAVA Socket Programming Joonbok Lee KAIST.
2: Application Layer 1 Socket Programming TCP and UDP.
Network Applications: UDP and TCP Socket Programming Y. Richard Yang 9/17/2013.
JAVA Socket Programming Source: by Joonbok Lee, KAIST, 2003.
ECE5650: Network Programming
1 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of.
2: Application Layer1 Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 2 nd edition. Jim Kurose, Keith Ross.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
CS 3830 Day 11 Introduction : Application Layer 2 Server-client vs. P2P: example Client upload rate = u, F/u = 1 hour, u s = 10u, d min ≥ u s.
Chapter 2 Application Layer Computer Networking: A Top Down Approach, 5 th edition. Jim Kurose, Keith Ross Addison-Wesley, April A note on the use.
Winter 2002Suprakash Datta1 Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
-1- Georgia State UniversitySensorweb Research Laboratory CSC4220/6220 Computer Networks Dr. WenZhan Song Associate Professor, Computer Science.
Socket Programming Lee, Sooyong
Network Programming and Sockets CPSC 363 Computer Networks Ellen Walker Hiram College (Includes figures from Computer Networking by Kurose & Ross, © Addison.
Socket Programming Tutorial. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Java Socket programming. Socket programming with TCP.
NETWORK PROGRAMMING.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
2: Application Layer1 Socket programming Socket API Explicitly created, used, released by apps Client/server paradigm Two types of transport service via.
1 CSCD 330 Network Programming Spring 2014 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 7 Application.
Network Applications: DNS, UDP Socket 1/24/ Outline  Recap r DNS r Network application programming: UDP.
Chapter 2 Application Layer Application 2-1. Chapter 2: Application layer 2.1 Principles of network applications 2.2 Web and HTTP 2.3 FTP 2.4 Electronic.
1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of.
1 COMP 431 Internet Services & Protocols Client/Server Computing & Socket Programming Jasleen Kaur February 2, 2016.
1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
Network Applications: DNS Details; UDP Network App Programming
Network Applications: Network App Programming: TCP FTP Y. Richard Yang 2/8/2016.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 11 Omar Meqdadi Department of Computer Science and Software Engineering University.
1 All rights reserved to Chun-Chuan Yang Upon completion you will be able to: The OSI Model and the TCP/IP Protocol Suite Understand the architecture of.
2: Application Layer1 Network applications: some jargon Process: program running within a host. r within same host, two processes communicate using interprocess.
Topic: Network programming
Socket Programming Socket Programming Overview
DNS: Domain Name System
Socket programming with TCP
Chapter 2: outline 2.1 principles of network applications
Socket programming - Java
CSCD 330 Network Programming
Socket Programming Socket Programming Overview
Socket Programming.
CSCD 330 Network Programming
Java Socket Programming
Socket Programming 2: Application Layer.
DNS: Domain Name System
CPSC 441 UDP Socket Programming
Chapter 2: Application layer
DNS: Domain Name System
DNS: Domain Name System
Socket Programming with UDP
Presentation transcript:

Client-Server Paradigm and Performance L. Grewe

2 Review: Basic Client-Server Request/Reply Paradigm Typical Internet app has two pieces: client and server application transport network data link physical application transport network data link physical Client (C): r initiates contact with server (“speaks first”) r typically requests service from a specific server r for Web, client is implemented in browser; for , in mail reader Server (S): r provides requested service to client r e.g., Web server sends requested Web page; mail server delivers request reply

3 Example: Electronic Mail Three major components: User agents Mail servers Protocols – Outgoing SMTP – Retrieving POP3: Post Office Protocol [RFC 1939] IMAP: Internet Mail Access Protocol [RFC 1730] user mailbox outgoing message queue mail server user agent user agent user agent mail server user agent user agent mail server user agent SMTP POP3 or IMAP SMTP

4 SMTP: Outgoing as a Client-Server Application S: 220 mr1.its.yale.edu C: HELO cyndra.yale.edu S: 250 Hello cyndra.cs.yale.edu, pleased to meet you C: MAIL FROM: S: 250 Sender ok C: RCPT TO: S: 250 Recipient ok C: DATA S: 354 Enter mail, end with "." on a line by itself C: Date: Wed, 23 Jan :20: (EST) C: From: "Y. R. Yang" C: To: "Y. R. Yang" C: Subject: This is subject C: C: This is the message body! C: Please don’t spoof! C: C:. S: 250 Message accepted for delivery C: QUIT S: 221 mr1.its.yale.edu closing connection

5 POP3 Protocol: Mail Access Authorization phase client commands: – user: declare username – pass: password server responses – +OK – -ERR Transaction phase, client: list: list message numbers retr: retrieve message by number dele: delete quit C: list S: S: S:. C: retr 1 S: S:. C: dele 1 C: retr 2 S: S:. C: dele 2 C: quit S: +OK POP3 server signing off S: +OK POP3 server ready C: user alice S: +OK C: pass hungry S: +OK user successfully logged on %openssl s_client –connect pop.gmail.com:995

6 Big Picture buffers, states buffers, states

Socket Programming with TCP Client must contact server server process must first be running server must have created welcome socket (door) that welcomes client’s contact Client contacts server by: creating client-local TCP socket specifying IP address, port number of server process When client creates socket: client TCP establishes connection to server TCP When contacted by client, server TCP creates new connection socket for server process to communicate with a specific client TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server application viewpoint

8 Big Picture: Connection-Oriented TCP

9 Connection-oriented TCP: Big Picture (C version) welcomeSocket=socket(): create socket bind(welcomeSocket, …): specify socket address/port server client TCP connection setup listen(welcomeSocket, …): specify that socket welcomeSocket is a listening socket connectionSocket=accept(welcomeSocket, …): get a connected connection from the queue for socket welcomeSocket; create a new socket identified by connectionSocket read()/write(): do IO on socket connectionSocket close(connectionSocket): done clientSocket=socket(): create socket bind(clientSocket): specify socket address connect(clientSocket, serverAddr, serverPort): initialize TCP handshake to server; return until TCP handshake is done read()/write(): do IO on clientSocket close(clientSocket): done optional

Client/server socket interaction: TCP wait for incoming connection request connectionSocket = welcomeSocket.accept() create socket, port= x, for incoming request: welcomeSocket = ServerSocket(x) create socket, connect to serv host, port= x clientSocket = Socket() close connectionSocket read reply from clientSocket close clientSocket Server (running on hostid ) Client send request using clientSocket read request from connectionSocket write reply to connectionSocket TCP connection setup

Server Flow connSocket = accept() Create ServerSocket(6789) read request from connSocket Serve the request close connSocket -Welcome socket: the waiting room -connSocket: the operation room

12 ServerSocket ServerSocket() – creates an unbound server socket. ServerSocket(int port) – creates a server socket, bound to the specified port. ServerSocket(int port, int backlog) – creates a server socket and binds it to the specified local port number, with the specified backlog. ServerSocket(int port, int backlog, InetAddress bindAddr) – create a server with the specified port, listen backlog, and local IP address to bind to. bind(SocketAddress endpoint) – binds the ServerSocket to a specific address (IP address and port number). bind(SocketAddress endpoint, int backlog) – binds the ServerSocket to a specific address (IP address and port number). Socket accept() – listens for a connection to be made to this socket and accepts it. close() closes this socket.

13 (Client)Socket Socket(InetAddress address, int port) creates a stream socket and connects it to the specified port number at the specified IP address. Socket(InetAddress address, int port, InetAddress localAddr, int localPort) creates a socket and connects it to the specified remote address on the specified remote port. Socket(String host, int port) creates a stream socket and connects it to the specified port number on the named host. bind(SocketAddress bindpoint) binds the socket to a local address. connect(SocketAddress endpoint) connects this socket to the server. connect(SocketAddress endpoint, int timeout) connects this socket to the server with a specified timeout value. InputStream getInputStream() returns an input stream for this socket. OutputStream getOutputStream() returns an output stream for this socket. close() closes this socket.

14 TCP Example Example client-server app: 1) client reads line from standard input ( inFromUser stream), sends to server via socket ( outToServer stream) 2) server reads line from socket 3) server converts line to uppercase, sends back to client 4) client reads, prints modified line from socket ( inFromServer stream)

Example: Java client (TCP) 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)); sentence = inFromUser.readLine(); Socket clientSocket = new Socket(“server.name", 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); Create input stream Create client socket, connect to server Create output stream attached to socket

Example: Java client (TCP), cont. outToServer.writeBytes(sentence + '\n'); BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); modifiedSentence = inFromServer.readLine(); System.out.println ("FROM SERVER: " + modifiedSentence ); clientSocket.close(); } Read line from server Create input stream attached to socket Send line to server

Example: Java server (TCP) import java.io.*; import java.net.*; class TCPServer { public static void main(String argv[]) throws Exception { String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); Create welcoming socket at port 6789 Wait, on welcoming socket for contact by client Create input stream, attached to socket

Example: Java server (TCP), cont clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + '\n'; DataOutputStream outToClient = new DataOutputStream (connectionSocket.getOutputStream()); outToClient.writeBytes(capitalizedSentence); } Read in line from socket Create output stream, attached to socket Write out line to socket End of while loop, loop back and wait for another client connection

Question How inter-operable is the sample program? 19

Byte to Data: Char/String Pay attention to encoding of data: transport layer handles only a sequence of bytes, the meaning of the bytes is by app. – String/char bytes depends on charset getBytes(“charset”) to get the correct char set java.nio.charset.Charset.defaultCharset() DataOutputStream writeBytes(String) truncates 20

Byte to Data: Data Integers may be represented differently – Big vs little endianness Example: int x = 0x0A0B0C0D What are the bytes? Typically network protocols are using big-endian order 21

Data Representation 22 String/CharInt/short Byte

Clients and Servers Get some sense of the dynamics of a basic client/server app

Server Model Some basic questions – How long is the queue at the welcome socket? – What is the response time of a request? 24 Welcome Socket (Queue)

Basic Modeling of C/S Assume that client requests arrive at a rate of lambda/second Assume that each request takes 1/mu seconds Some basic questions – How long is the queue at the welcome socket? – What is the response time of a request? 25 Welcome Socket Queue

Basic Modeling of C/S We are not interested in extremely precise modeling, but want intuition Assume that arrival and service patterns: memory less – During a small interval  t, the probability of a new arrival is:  t – During a small interval  t, the probability of a current call finishes is:  t 26

Analysis of Queue Length for C/S 27 01kN system state: # of requests queued at the welcome socket of the server p0p0 p1p1 pkpk k+1 p k+1  pNpN

Backup 28

29 UDP close clientSocket Server (running on hostid ) read reply from clientSocket create socket, clientSocket = DatagramSocket() Client Create datagram using (serv host, x) as (dest addr. port), send request using clientSocket create socket, port= x, for incoming request: serverSocket = DatagramSocket( x ) read request from serverSocket write reply to serverSocket r Create socket with port number: DatagramSocket sSock = new DatagramSocket(9876); r If no port number is specified, the OS will pick one generate reply, create datagram using client host address, port number

30 Example: UDPClient.java r A simple UDP client which reads input from keyboard, sends the input to server, and reads the reply back from the server.

31 Example: Java client (UDP) import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); String sentence = inFromUser.readLine(); byte[] sendData = new byte[1024]; sendData = sentence.getBytes(); DatagramSocket clientSocket = new DatagramSocket(); InetAddress sIPAddress = InetAddress.getByName(“servname"); Create input stream Create client socket Translate hostname to IP address using DNS

32 Example: Java client (UDP), cont. DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, sIPAddress, 9876); clientSocket.send(sendPacket); byte[] receiveData = new byte[1024]; DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); } Create datagram with data-to-send, length, IP addr, port Send datagram to server Read datagram from server

33 Example: UDPServer.java A simple UDP server which changes any received sentence to upper case.

34 Example: Java server (UDP) import java.io.*; import java.net.*; class UDPServer { public static void main(String args[]) throws Exception { DatagramSocket serverSocket = new DatagramSocket(9876); byte[] receiveData = new byte[1024]; byte[] sendData = new byte[1024]; while(true) { DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); Create datagram socket at port 9876 Create space for received datagram Receive datagram

35 Example: Java server (UDP), cont String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase(); sendData = capitalizedSentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); serverSocket.send(sendPacket); } Get IP addr port #, of sender Write out datagram to socket End of while loop, loop back and wait for another datagram Create datagram to send to client

36 UDP Connectionless Demux DatagramSocket serverSocket = new DatagramSocket(9876); Client IP:B P2 client IP: A P1 P3 server IP: S SP: 9876 DP: 9157 SP: 9157 DP: 9876 SP: 9876 DP: 5775 SP: 5775 DP: 9876 Source Port (SP) provides “return address”

37 UDP Provides Multiplexing/Demultiplexing server client UDP socket space address: {*:9876} snd/recv buf: address: { :53} snd/recv buf: UDP socket space address: { :1500} snd/recv buf: address: { :4343} snd/recv buf: Packet demutiplexing is based on (dst address, dst port) at dst %netstat –u –n -a local address local port