Client/Server Design Issues Based on Java Network Programming and Distributed Computing, Chapter 6 Also Online Java Tutorial, Sun.

Slides:



Advertisements
Similar presentations
Introduction 1 Lecture 13 Transport Layer (Transmission Control Protocol) slides are modified from J. Kurose & K. Ross University of Nevada – Reno Computer.
Advertisements

Remote Procedure Call (RPC)
CCNA – Network Fundamentals
Guide to TCP/IP, Third Edition
UDP & TCP Where would we be without them!. UDP User Datagram Protocol.
Transport Layer – TCP (Part1) Dr. Sanjay P. Ahuja, Ph.D. Fidelity National Financial Distinguished Professor of CIS School of Computing, UNF.
Slide 1 Client / Server Paradigm. Slide 2 Outline: Client / Server Paradigm Client / Server Model of Interaction Server Design Issues C/ S Points of Interaction.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 OSI Transport Layer Network Fundamentals – Chapter 4.
Lecture 17 Client/Server Programming Chat CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Socket Programming.
User Datagram Protocol. Introduction UDP is a connectionless transport protocol, i.e. it doesn't guarantee either packet delivery or that packets arrive.
Prepared By E. Musa Alyaman1 User Datagram Protocol (UDP) Chapter 5.
1 Java Networking – Part I CS , Spring 2008/9.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
McGraw-Hill©The McGraw-Hill Companies, Inc., 2004 Application Layer PART VI.
William Stallings Data and Computer Communications 7 th Edition (Selected slides used for lectures at Bina Nusantara University) Transport Layer.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Department of Electronic Engineering City University of Hong Kong EE3900 Computer Networks Transport Protocols Slide 1 Transport Protocols.
TCP. Learning objectives Reliable Transport in TCP TCP flow and Congestion Control.
Computer Network Architecture and Programming
WXES2106 Network Technology Semester /2005 Chapter 8 Intermediate TCP CCNA2: Module 10.
Client Server Model and Software Design TCP/IP allows a programmer to establish communication between two application and to pass data back and forth.
Gursharan Singh Tatla Transport Layer 16-May
Chapter 26 Client Server Interaction Communication across a computer network requires a pair of application programs to cooperate. One application on one.
TRANSPORT LAYER T.Najah Al-Subaie Kingdom of Saudi Arabia Prince Norah bint Abdul Rahman University College of Computer Since and Information System NET331.
1 Chapter Internetworking Part 4 (Transport Protocols, UDP and TCP, Protocol Port Numbers)
Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.
1 Transport Layer Computer Networks. 2 Where are we?
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
6.1. Transport Control Protocol (TCP) It is the most widely used transport protocol in the world. Provides reliable end to end connection between two hosts.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 OSI Transport Layer Network Fundamentals – Chapter 4.
TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 2.5 Internetworking Chapter 25 (Transport Protocols, UDP and TCP, Protocol Port Numbers)
More on Socket API. How to Place Timeouts on Sockets (1)  Using SIGALRM signal Connection timeout 기간의 축소 Response timeout advio/dgclitimeo3.clib/connect_timeo.c.
Copyright 2002, S.D. Personick. All Rights Reserved.1 Telecommunications Networking II Topic 20 Transmission Control Protocol (TCP) Ref: Tanenbaum pp:
TCP1 Transmission Control Protocol (TCP). TCP2 Outline Transmission Control Protocol.
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
Socket Programming Using JAVA Asma Shakil Semester 1, 2008/2009.
The InetAddress Class A class for storing and managing internet addresses (both as IP numbers and as names). The are no constructors but “class factory”
Sockets For Clients Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
1 Socket Options Ref: Chapter 7. 2 Socket Options Various attributes that are used to determine the behavior of sockets.Various attributes that are used.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
Part 4: Network Applications Client-server interaction, example applications.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
4343 X2 – The Transport Layer Tanenbaum Ch.6.
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
1 Kyung Hee University Chapter 11 User Datagram Protocol.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
TCP/IP1 Address Resolution Protocol Internet uses IP address to recognize a computer. But IP address needs to be translated to physical address (NIC).
1 K. Salah Application Layer Module K. Salah Network layer duties.
Chapter 9 The Transport Layer The Internet Protocol has three main protocols that run on top of IP: two are for data, one for control.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
1 Chapter 24 Internetworking Part 4 (Transport Protocols, UDP and TCP, Protocol Port Numbers)
1 Issues in Client/Server Refs: Chapter 27 Case Studies RFCs.
Object-Orientated Analysis, Design and Programming
Chapter 9: Transport Layer
Instructor Materials Chapter 9: Transport Layer
Socket Option.
Lecture 4 Socket Programming Issues
Issues in Client/Server Programming
CPEG514 Advanced Computer Networkst
Transport Layer 9/22/2019.
Exceptions and networking
Presentation transcript:

Client/Server Design Issues Based on Java Network Programming and Distributed Computing, Chapter 6 Also Online Java Tutorial, Sun.

Spring 2006CPE Special Topics in Computer Engineering2 Topics l Socket Constructors l Socket Options l Issues in Client/Server Programming

Spring 2006CPE Special Topics in Computer Engineering3 Socket Class: Commonly Used Socket Class: Commonly Used Constructors I l Socket (InetAddress address, int port) throws java.io.IOException, Java.lang.SecurityException –creates a socket connected to the specified IP address and port –an exception is thrown if u a connection cannot be established or u connecting to that host violates a security restriction (e.g. when an applet tries to connect to a machine other than the machine from which it was loaded)

Spring 2006CPE Special Topics in Computer Engineering4 Socket Class: Commonly Used Socket Class: Commonly Used Constructors II l Socket (InetAddress address, int port, InetAddress localAddress, int locaPort) throws java.io.IOException, javaJang.SecurityException –creates a socket connected to the specified IP address and port –bound to the specified local address and local port u useful in the case of multi-horned hosts (i.e., a machine where the localhost is known by two or more IP addresses).

Spring 2006CPE Special Topics in Computer Engineering5 Socket Class: Commonly Used Socket Class: Commonly Used Constructors III l Socket (String host, int port) throws java.net.UnknownHostException, java.io.IOException, javaJang.SecurityException –allows a string to be specified, rather than an InetAddress –exception thrown u host name could not be resolved u a connection could not be established u a security restriction is violated

Spring 2006CPE Special Topics in Computer Engineering6 Socket Class: Commonly Used Socket Class: Commonly Used Constructors IV l Socket (String host, int port, InetAddress localAddress, int locaPort) throws java.net.UnknownHostException, java.io.IOException, javaJang.SecurityException –creates a socket connected to the specified IP address and port –bound to the specified local address and local port u useful in the case of multi-horned hosts (i.e., a machine where the localhost is known by two or more IP addresses).

Spring 2006CPE Special Topics in Computer Engineering7 Creating a Socket Under normal circumstances a socket is connected to a remote machine and port when it is created l Call to a socket constructor will return as soon as a connection is established l If remote machine is not responding –Constructor method may block for an indefinite amount of time –No guarantee how long a socket may block for –In mission-critical systems, place such calls in a second thread, to prevent an application from stalling

Spring 2006CPE Special Topics in Computer Engineering8 Using a Socket: Some Methods l void close() throws java.io.IOException – closes connection u may or may not allow remaining data to be sent u flush any output streams before closing a socket connection l InetAddress getlnetAddress() –returns the address of the remote machine l InputStream getlnputstream() throws java.io.I0Exception –returns an input stream, which reads from the application this socket is connected to l OutputStream getoutputStream() throws java.io.IOException –returns an output stream, which writes to the application that this socket is connected to l More methods: See relevant Sun Documentation

Spring 2006CPE Special Topics in Computer Engineering9 l It's important to know about some of these topics, although it might not be apparent how and when to use them. l Details are in Sun documentation - we are just trying to get some idea of what can be done. TCP Socket Options

Spring 2006CPE Special Topics in Computer Engineering10 Socket Options l Various attributes that are used to determine the behavior of sockets. –i.e. settings that modify how sockets work l Setting options tells the OS/Protocol Stack the behavior we want.

Spring 2006CPE Special Topics in Computer Engineering11 Option types l Many socket options are boolean flags indicating whether some feature is enabled (true) or disabled (false). l Other options are associated with different data types, e.g. int, representing time. l Some options are readable only (we can’t set the value).

Spring 2006CPE Special Topics in Computer Engineering12 Setting and Getting option values Examples: l To increase the receive buffer size to 4,096 bytes.setReceiveBufferSize(4096); someSocket.setReceiveBufferSize(4096); l To determine the size of the current receive buffer int size = someSocket.getReceiveBufferSize();

Spring 2006CPE Special Topics in Computer Engineering13 Some Options l SO_KEEPALIVE l SO_RCVBUF l SO_SNDBUF l SO_LINGER l SO_TIMEOUT

Spring 2006CPE Special Topics in Computer Engineering14 SO_KEEPALIVE someSocket.setSoKeepAlive(true); l Boolean option: enabled means that a socket should send a probe to peer if no data flow for a “long time”. l Used by TCP - allows a process to determine whether peer process/host has crashed. –Application doesn’t have any control over how often KEEPALIVE probes are sent. –A better solution than KEEPALIVE is to instead modify the timeout socket option.

Spring 2006CPE Special Topics in Computer Engineering15 SO_RCVBUF SO_SNDBUF l Integer values options – request to change the receive and send buffer sizes. –Change is not guaranteed u Some operating systems may not allow this socket option to be modified –Ignore any requests to change value l Can be used with TCP and UDP sockets l With TCP, this option effects the window size used for flow control - must be established before connection is made. –someSocket.{g|s}et{Send|Receive}BufferSize(..);

Spring 2006CPE Special Topics in Computer Engineering16 SO_LINGER l Used to control whether and how long a call to close will wait for pending ACKS. l connection-oriented sockets only. l setSoLinger(boolean onFlag, int duration); l getSoLinger(); returns duration (-1 if option is disabled)

Spring 2006CPE Special Topics in Computer Engineering17 SO_LINGER l If a TCP socket connection is closed, data may still be queued for delivery (e.g. IP datagram lost and must be resent). u SO_LINGER option used to control whether and how long a call to close will wait for pending ACKS. l connection-oriented sockets only. l setSoLinger(boolean onFlag, int duration); // Enable linger, for fifty seconds someSocket.setSoLinger( true, 50 ); l getSoLinger(); returns duration (-1 if option is disabled)

Spring 2006CPE Special Topics in Computer Engineering18 SO_LINGER usage l Disables/enables immediate return from a close() of a TCP Socket. –Enabling this option with a non-zero Integer timeout means that a close() will block pending the transmission and acknowledgement of all data written to the peer, at which point the socket is closed gracefully. –Upon reaching the linger timeout, the socket is closed forcefully, with a TCP RST. l Enabling the option with a timeout of zero does a forceful close immediately. l If the specified timeout value exceeds 65,535 it will be reduced to 65,535.

Spring 2006CPE Special Topics in Computer Engineering19 SO_TIMEOUT l By default, I/O operations are blocking. –An attempt to read data from an InputStream will wait indefinitely until input arrives u If the input never arrives, the application stalls (unless multi- threading is used). l Enable SO_TIMEOUT option –A read request to the InputStream of a socket starts a timer –When no data arrives in time and the timer expires, a java.io.InterruptedIOException is thrown u retry IO u notify user u connection aborted

Spring 2006CPE Special Topics in Computer Engineering20 SO_TIMEOUT (cont.) l Used to tell the socket to use non-blocking read. l getSoTimeout() returns the current setting (by default 0, or disabled, representing a blocking read). –e.g. to tell socket to interrupt reading if 5 seconds pass by, use: mySocket.setSoTimeout(5000);

Spring 2006CPE Special Topics in Computer Engineering21 Nagle’s Algorithm l When using IP datagrams, overhead exists for each packet (e.g. IP and TCP header information) l If only a few bytes at a time are sent in each packet, the size of the header information will far exceed that of the data.

Spring 2006CPE Special Topics in Computer Engineering22 Nagle’s Algorithm (cont.) l TCP may send only one datagram at a time –When an acknowledgment comes back for each IP datagram u A new packet is sent containing any data that has been queued up. l Bandwidth consumed by packet header information is decreased l Network latency increased l Systems that require quick response times (e.g. telnet) are slowed –TCP_NODELAY Socket Option is used to disable Nagle’s algorithm

Spring 2006CPE Special Topics in Computer Engineering23 TCP_NODELAY Socket Option // Disable Nagle’s algorithm for faster response times someSocket.setTcpNoDelay(false); // Get the state of the TCP_NODELAY flag boolean state = someSocket.getTcpNoDelay();

Spring 2006CPE Special Topics in Computer Engineering24 l This was just an overview –there are many details associated with the options described. –There are many options that haven’t been described. –UNIX Network Programming is one of the best sources of information about socket options. Socket Options Summary Not ALL options are (fully) supported by Java.

Spring 2006CPE Special Topics in Computer Engineering25 Issues in Client Programming l Identifying the Server. l Looking up an IP address. l Looking up a well known port name. l Specifying a local IP address l UDP client design. l TCP client design.

Spring 2006CPE Special Topics in Computer Engineering26 Identifying a TCP/IP server l Need an IP address, protocol and port. –We often use host names instead of IP addresses. –usually the protocol (UDP vs. TCP) is not specified by the user. –often the port is not specified by the user.

Spring 2006CPE Special Topics in Computer Engineering27 Services and Ports l Many services are available via “well known” addresses (names). l There is a mapping of service names to port numbers.

Spring 2006CPE Special Topics in Computer Engineering28 Specifying a Local Address l When a client creates and binds a socket it must specify a local port and IP address. l Typically a client doesn’t care what port it is on: mySocket = new DatagramSocket() give me any available port !

Spring 2006CPE Special Topics in Computer Engineering29 Local IP address l A client can also ask the operating system to take care of specifying the local IP address: myAddress = InetAddress.getLocalHost(); Give me the appropriate address

Spring 2006CPE Special Topics in Computer Engineering30 UDP Client Design l Establish server address (IP and port). l Allocate a socket. l Communicate with server (send, receive) l Close the socket.

Spring 2006CPE Special Topics in Computer Engineering31 TCP Client Design l Establish server address (IP and port). l Allocate a socket. l Communicate with server (through given streams). l Close the connection.

Spring 2006CPE Special Topics in Computer Engineering32 Closing a TCP socket l Many TCP based application protocols support multiple requests and/or variable length requests over a single TCP connection. l How does the server known when the client is done (and it is OK to close the socket) ?

Spring 2006CPE Special Topics in Computer Engineering33 Partial Close l One solution is for the client to shut down only it’s writing end of the socket. l The socket call provides this function. l The shutdownOutput() socket call provides this function. mySocket.shutdownOutput(); mySocket.shutdownOutput(); –shutdownOutput() flushes output stream and sends TCP-connection termination sequence. –shutdownInput() closes input stream and discards any further information (further read()s will get -1)

Spring 2006CPE Special Topics in Computer Engineering34 Server Design IterativeConnectionlessIterativeConnection-Oriented ConcurrentConnection-OrientedConcurrentConnectionless

Spring 2006CPE Special Topics in Computer Engineering35 Concurrent vs. Iterative Iterative Small, fixed size requests Easy to program Iterative Small, fixed size requests Easy to program Concurrent Large or variable size requests Harder to program Typically uses more system resources Concurrent Large or variable size requests Harder to program Typically uses more system resources

Spring 2006CPE Special Topics in Computer Engineering36 Connectionless vs. Connection-Oriented Connection-Oriented EASY TO PROGRAM transport protocol handles the tough stuff. requires separate socket for each connection. Connection-Oriented EASY TO PROGRAM transport protocol handles the tough stuff. requires separate socket for each connection. Connectionless less overhead no limitation on number of clients Connectionless less overhead no limitation on number of clients

Spring 2006CPE Special Topics in Computer Engineering37 Statelessness l State: Information that a server maintains about the status of ongoing client interactions. l Connectionless servers that keep state information must be designed carefully! Messages can be duplicated!

Spring 2006CPE Special Topics in Computer Engineering38 The Dangers of Statefullness l Clients can go down at any time. l Client hosts can reboot many times. l The network can lose messages. l The network can duplicate messages.

Spring 2006CPE Special Topics in Computer Engineering39 Concurrent Server Design Alternatives One process per client Spawn one thread per client Preforking multiple processes Prethreaded Server

Spring 2006CPE Special Topics in Computer Engineering40 One child process per client l Traditional Unix server l Parent process needs to clean up after children!!!!

Spring 2006CPE Special Topics in Computer Engineering41 One thread per client l Use new Thread().start(); l Using threads makes it easier (less overhead) to have sibling processes share information. l Sharing information must be done carefully (use synchronized) Watch out for deadlocks!

Spring 2006CPE Special Topics in Computer Engineering42 Pre-threaded Server l Can have the main thread do all the calls to accept() and hand off each client to an existing thread.

Spring 2006CPE Special Topics in Computer Engineering43 What’s the best server design for my application? l Many factors: –Expected number of simultaneous clients. –Transaction size (time to compute or lookup the answer) –Variability in transaction size. –Available system resources (what resources can be required in order to run the service).

Spring 2006CPE Special Topics in Computer Engineering44 Server Design l It is important to understand the issues and options. l Knowledge of queuing theory can be a big help. l You might need to test a few alternatives to determine the best design.