Unformatted text preview:

Client Server Paradigm and Performance L Grewe Review Basic Client Server Request Reply Paradigm Typical Internet app has two pieces client and server Client C initiates contact with server speaks first typically requests service from a specific server for Web client is implemented in browser for e mail in mail reader Server S provides requested service to client e g Web server sends requested Web page mail server delivers e mail applicatio n transport network data link physical request reply applicatio n transport network data link physical 2 outgoing message queue Example Electronic Mail Three major components User agents Mail servers Protocols Outgoing email user agent mail server POP3 Post Office Protocol RFC 1939 IMAP Internet Mail Access Protocol RFC 1730 user agent SMTP mail server user agent SMTP SMTP Retrieving email user mailbox SMTP mail server user agent POP3 or IMAP SMTP user agent user agent 3 SMTP Outgoing Email as a Client Server Application S C S C S C S C S C C C C C C C C C S C S 220 mr1 its yale edu HELO cyndra yale edu 250 Hello cyndra cs yale edu pleased to meet you MAIL FROM spoof cs yale edu 250 spoof cs yale edu Sender ok RCPT TO yry yale edu 250 yry yale edu Recipient ok DATA 354 Enter mail end with on a line by itself Date Wed 23 Jan 2008 11 20 27 0500 EST From Y R Yang yry cs yale edu To Y R Yang yry cs yale edu Subject This is subject This is the message body Please don t spoof 250 Message accepted for delivery QUIT 221 mr1 its yale edu closing connection 4 POP3 Protocol Mail Access Authorization phase client commands user declare username pass password server responses OK ERR S C S C S OK POP3 server ready user alice OK pass hungry OK user successfully logged C list S 1 498 S 2 912 S Transaction phase client C retr 1 S message 1 contents list list message numbers S retr retrieve message by C dele 1 number C retr 2 S message 1 contents dele delete S quit C dele 2 C quit S OK POP3 server signing off openssl s client connect pop gmail com 995 on 5 Big Picture buffers states buffers states 6 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 application viewpoint TCP provides reliable in order transfer of bytes pipe between client and server Big Picture Connection Oriented TCP 8 Connection oriented TCP Big Picture C version server client welcomeSocket socket create socket bind welcomeSocket specify socket address port listen welcomeSocket specify that socket welcomeSocket is a listening socket TCP connection setup connectionSocket accept welcomeSocket get a connected connection from the queue for socket welcomeSocket create a new socket identified by connectionSocket clientSocket socket create socket bind clientSocket specify socket address optional connect clientSocket serverAddr serverPort initialize TCP handshake to server return until TCP handshake is done read write do IO on clientSocket read write do IO on socket connectionSocket close clientSocket done close connectionSocket done 9 Client server socket interaction TCP Server running on hostid Client create socket port x for incoming request welcomeSocket ServerSocket x TCP wait for incoming connection setup connection request connectionSocket welcomeSocket accept read request from connectionSocket write reply to connectionSocket close connectionSocket create socket connect to servhost port x clientSocket Socket send request using clientSocket read reply from clientSocket close clientSocket Server Flow Create ServerSocket 6789 connSocket accept read request from connSocket Welcome socket the waiting room connSocket the operation room Serve the request close connSocket ServerSocket ServerSocket ServerSocket int port binds the ServerSocket to a specific address IP address and port number Socket accept binds the ServerSocket to a specific address IP address and port number bind SocketAddress endpoint int backlog create a server with the specified port listen backlog and local IP address to bind to bind SocketAddress endpoint creates a server socket and binds it to the specified local port number with the specified backlog ServerSocket int port int backlog InetAddress bindAddr creates a server socket bound to the specified port ServerSocket int port int backlog creates an unbound server socket listens for a connection to be made to this socket and accepts it close closes this socket 12 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 13 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 14 Example Java client TCP import java io import java net class TCPClient public static void main String argv throws Exception String sentence String modifiedSentence Create input stream Create client socket connect to server Create output stream attached to socket BufferedReader inFromUser new BufferedReader new InputStreamReader System in sentence inFromUser readLine Socket clientSocket new Socket server name 6789 DataOutputStream outToServer new DataOutputStream clientSocket getOutputStream Example Java client TCP cont Send line to server outToServer writeBytes sentence n BufferedReader


View Full Document

Cal State East Bay CS 6320 - Paradigm and Performance

Loading Unlocking...
Login

Join to view Paradigm and Performance and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Paradigm and Performance and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?