`
`Thesis
`Master of Science in Computer Science
`
`Client-Server Applications in Java
`
`by
`Jasmine J. Ahuja
`
`Advisor
`Dr. Howard Blum
`
`December 1997
`
`0001
`
`Apple/Twitter
`Ex. 1028
`IPR1 of U.S. Pat. No. 8,612,515
`
`
`
` CONTENTS
`
`Introduction
`
`Overview of Concepts
`2.1
`Distributed Applications
`2.2
`The Java Language
`2.3 World Wide Web
`2.4
`Client-Server
`
`Java vs. C++
`
`Communication between Client and Server using sockets and Java Server
`application
`4.1
`Client as Java Application (Non Web)
`4.2
`Client as Web Browser (using Telnet Applet)
`4.3
`Client as Web Browser (using Java Applet)
`
`Sample Applications
`Client as Java Application (Non Web)
`Client as Web Browser (using Telnet Applet)
`Client as Web Browser (using Java Applet)
`
`Some other methods of communication between Client and Server
`5.1
`CGI Scripts
`5.2
`Remote Method Invocation
`
`Miscellaneous Concerns
`
` Recommendations for future studies
`
` Bibliography
`
`1.
`
`2.
`
`3.
`
`4.
`
`5.
`
`6.
`
`7.
`
`8.
`
`9.
`
`Appendix
`A. Code for Version 1- Client as a Java Application
`A.1 Client
`
`A.2 Server
`B. Code for Version 2- Client as a Web Browser (Telnet Applet)
` B.1 Client
` B.2 Server
`C. Code for Version 3- Client as a Web Browser (Java Applet)
`C.1 Client
` C.2 Server
`
`0002
`
`
`
`Client-Server Applications in Java
`
`1.
`
`Introduction
`
`During the first two decades of their existence, computer systems were highly centralized. A computer was
`usually placed within a large room and the information to be processed had to be taken to it. This had two
`major flaws, a) the concept of a single large computer doing all the work and b) the idea of users bringing
`work to the computer instead of bringing the computer to the user.
`
`This was followed by ‘stand alone PCs’ where the complete application had to be loaded on to a single
`machine. Each user had his/her own copy of the software. The major problems were a) sharing
`information and b) redundancy.
`
`These two concepts are now being balanced by a new concept called computer networks. In computer
`networking a large number of separate but interconnected computers work together. An application that
`requires two or more computers on the network is called a network application. The client–server model is
`a standard model for network applications. A server is a process that is waiting to be contacted by a client
`process so that the server can do something for it. A client is a process that sends a request to the server.
`The idea behind a network application is to offload some utilities like the Graphical User Interface (GUI)
`and in some cases, some processing, from the server to the client. As a result the GUI can be elaborate, thus
`making the application more user friendly. The other issues involved in client-servers are inter-process
`communication, security, maintenance and requirement for special software to run the client.
`
`In a ‘conventional’ client–server model, a copy of the client process lies on every client machine and the
`client sends a request to the server through a socket to the port that the server is listening on. This model is
`popular as it offers improved graphical user interface. However, it has the following
`disadvantages: a) a copy of the client process has to be installed on every user’s machine and b) any
`modification or update to the client process needs to be distributed and installed on every client machine.
`
`In a new, modified view, there is no preinstalled client on the client machine. The client process is loaded
`onto the client machine each and every time the user initiates a request through his/her web browser using
`the server’s URL/IP address. This ‘web oriented view’ does not require the user to have a special software
`to run the application. Moreover maintenance is much easier. The server’s administrator can ensure that
`the users always download the latest version of the client.
`
`In this paper, attempt has been made to study the basic issues and requirements for design and development
`of web oriented client-server applications and to examine the Java language in the context of these
`requirements. This paper especially concentrates on the inter-process communication and the user
`interface.
`
`The paper starts with an overview of concepts commonly used in networking. It goes on to discuss
`communications using sockets in detail and three alternative Java based examples of client-server
`implementation. The first example is a conventional client-server in which the client as well as the server
`are applications. The second example is web based, where the client is the web browser and the server is an
`application and they use HTML and a Telnet applet to communicate. The third example is also web based,
`but uses a Java applet along with the HTML. The paper also discusses other methods of communication
`like Remote Method Invocation and CGI scripts in brief. Finally a discussion on applet security is followed
`by ideas for further studies in this field.
`
`1
`0003
`
`
`
`2.
`
`Overview of Concepts
`
`2.1
`
`Distributed Applications
`
`The term distributed applications, is used for applications that require two or more autonomous computers
`or processes to cooperate in order to run them. Thus, the distributed system considered in this paper,
`involves three resources, processing, data and user interface. Both processing and data can be distributed
`over many computers. The user interface is usually local to the user so that the graphical interface, which
`consumes high bandwidth, does not have to be transmitted from one location to another.
`
`
`
`
`
`
`
`A Typical Distributed Application Scenario
`
`Modem
`
`Workstation
`Client
`
`Internet/LAN
`
`Server
`
`In distributed computing, the computer network is used to support the execution of program units, called
`processes, that cooperate with one another to work towards a common goal. This approach has become
`popular due to a number of developments like:
`(cid:57) Increase in the number of personal computers
`(cid:57) Low cost of establishing computer networks with the advancement of technology
`(cid:57) Computer manufacturers now offer networking software as a part of the basic operating system
`(cid:57) Computer networks are now an established way of disseminating information
`
`2.2
`
`The Java Language [22]
`
`Java is a new programming language invented by Sun Microsystems. Sun’s goal was to allow programmers
`to create one copy of a program that users could run on almost any computer and operating system. This
`capability was designed to make Java a vital component of programmability on the Web.
`
`2
`0004
`
`
`
`The Java Language (contd.)
`
`Programs written in Java are translated into their own native architecture, in a format called bytecodes. In
`order to run a Java program, the user needs another program that can interpret the Java program and
`provide it with the environment and services it needs. The software layer, the Java Virtual Machine (JVM),
`makes just about any hardware and software platform look the same to the Java program. In effect, a JVM
`is a device driver for Java programs. Running a Java program with a JVM is currently slower than running
`an equivalent C program, but JVM technology is improving at a rapid pace.
`
`Java does not support pointers to memory and so Java programs cannot corrupt a computer’s memory. It
`also ensures all array and string references are within each item’s bound. It performs automatic garbage
`collection, which frees up unused memory, so Java programs cannot leak resources.
`
`Java’s potential of platform-independent bytecodes and a language designed to go hand in hand with the
`Internet is enormous. However, it is still a new language and has not been tested on very large projects
`where applications can migrate over many platforms. It is only when its tools are tested thoroughly will
`businesses be willing to adopt it as ‘the’ programming language of the future.
`
`2.3 World Wide Web [15]
`
`The World Wide Web can be briefly described as a global, interactive, dynamic, cross-platform,
`distributed, graphical hypertext information system that runs over the Internet. The primary concept behind
`the World Wide Web is hypertext – i.e. instead of reading text in a rigid, linear structure (e.g. a book), the
`user can easily skip from one point to another using available links. The Web is not limited to any one kind
`of machine, it can be accessed using an application called a browser like Netscape’s Navigator. It is
`successful in providing so much information because information is distributed globally across thousands
`of sites. The users do not have to install anything, they can go to a particular site to view information and
`when they are done their system reclaims the disk space. Information on the Web can be updated any time
`as it is contained on the site that published it and thus is accessible to the administrator of the site.
`
`No single entity “owns” the World Wide Web. Given the enormous number of independent sites that
`supply information to the Web, it is impossible for any single organization to set rules or guidelines. There
`is however, a World Wide Web (W3) Consortium, based at MIT (USA) and INRIA (Europe). The
`Consortium is a congregation of individuals and organizations interested in supporting and defining the
`languages and protocols that make the Web (HTTP, HTML etc). The W3 Consortium also provides
`products (browsers, server and so on) that are freely available to anyone who wants to use them.
`
`2.4
`
`Client-Server
`
`The client–server model is a standard model for network applications. A server is a process that is
`continuously running and waiting to be contacted by a client process. A client process initiates contact with
`the server by connecting to it at a specified port.
`
`3
`0005
`
`
`
`Client–Server (contd.)
`
`The following is a typical scenario:
`
`a) The server process is started on a computer system. It initializes itself and then waits for a client
`process to contact it with a service request.
`b) The client process, usually started on another system, is connected to the server’s system over a
`network. The client process sends a request across the network to the server requesting service of
`some form, e.g. reading or writing a file on the server’s system.
`c) When the server finishes processing the request, it waits for the next client request to arrive.
`
`Client-Server Environment
`
`Client
`
`Client
`
`Internet/LAN
`
`Modem
`
`Client
`
`Client
`
`Workstation
`Client
`
`Modem
`
`Client
`
`The server can be divided into two types:
`
`Server
`
`a) When a client’s request can be handled by the server in a short amount of time, the server process
`handles the request itself. This sequential or non-concurrent server handles one client request at a time
`e.g. returning the time -of-day to the client.
`
`b) When the amount of time to service a client depends on the client, e.g. a bank ATM where the user
`may take his/her own time to enter information or make a transaction, the server handles it in a
`concurrent fashion. Concurrent servers invoke another process (a child process) to handle each client
`request, so that the parent server process can go back to waiting for the next client request. This server
`requires an operating system that allows multiple processes to run at the same time.
`
`In a majority of applications, the client handles most of the user interface but may also take over a part of
`the processing from the server in some cases.
`
`4
`0006
`
`
`
`3.
`
`Java vs. C++
`
`Java is similar to C++ to some degree, which carries the benefit of it being familiar to many programmers.
`This section describes some features of Java relevant to the topic and points out where the language
`diverges from its ancestor C++.
`
`Syntax
`Java was designed to resemble C++, probably the most commonly used language today, in order to make
`the system more comprehensible.
`
`Object-Oriented
`Java is an object oriented programming language i.e. focus is on data in the application and methods that
`manipulate that data, rather than strictly on procedures. The object-oriented facilities of Java are essentially
`those of C++, with extensions from Objective C for more dynamic method resolution.
`
`Network-Oriented
`Java’s net class, which is a part of the java package, makes networking easier in Java than in C++. Sample
`code for setting up a simple server to listen on a port in C++ and Java is shown below:
`
`C++ ->
`
`#include <socket.h>
`
`main() /* a non-concurrent stream server */
`{ int sockfd, newsockfd, clilen;
` struct sockaddr_in cli_addr, serv_addr;
` if ((sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0)
` error("server: cannot open socket");
` bzero( (char *)&serv_addr, sizeof(serv_addr));
` serv_addr.sin_family = AF_INET;
` serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
` serv_addr.sin_port =htons(SERV_TCP_PORT);
` if(bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
` error( "server: cannot bind address");
` listen(sockfd, 5);
` for(;;) {
` clilen = sizeof(cli_addr);
` newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
` if (newsockfd < 0)
` error("server: cannot accept connection");
` str_echo(newsockfd); /* serve a client */
` close(newsockfd);
` }
`
`} J
`
`ava->
`
`import java.net.*;
`
`public static void main(String[] args)
`
`5
`0007
`
`
`
`Java vs. C++ (contd.)
`
`public void runServer()
`{ ServerSocket server;
` Socket connection;
` try {
` server = new ServerSocket( port, number of users);
` for(;;)
` { connection = server.accept();
` display.setText( "Connection received...\n" );
`
`
`
`
`// Serve the client
` display.appendText("\nClosing socket.\n" );
` connection.close();
` }
` }catch ( IOException e ) { e.printStackTrace(); }
` }
`
`{
`
`} T
`
`o be fair, this C++ code uses a larger number of parameters and statements because it is more general,
`allowing selection of a number of protocol suites, TCP/IP being one. Furthermore, within the TCP/IP suite
`either connection oriented TCP or connectionless UDP may be selected. The Java library however, has
`separate classes specializing in UDP (e.g. DatagramSocket, DatagramPacket) and TCP (e.g. ServerSocket,
`Socket).
`
`Secure
`Java is intended for use in networked/distributed environments. Towards that end, a lot of emphasis has
`been placed on security. Java enables the construction of virus-free, tamper-free systems. The
`authentication techniques are based on public-key encryption. Changes to the semantics of pointers make it
`impossible for applications to forge access to data structures or to access private data in objects that they do
`not have access to. This closes the door on most activities of viruses.
`
`Portable
`Being architecture neutral plays a major role in being portable. Unlike C and C++, there are no
`"implementation dependent" aspects of the specification. The sizes of the primitive data types are specified,
`as is the behavior of arithmetic on them. For example, "int" always means a signed two's complement 32
`bit integer. Making these choices is feasible in this day and age because essentially all CPUs share these
`characteristics. The Java system itself is quite portable. The compiler is written in Java and the runtime is
`written in ANSI C with a clean portability boundary. The portability boundary is essentially a POSIX
`subset.
`
`Interpreted
`Unlike the C++ compiler, the Java compiler generates bytecodes which are translated at runtime to native
`machine instructions (interpreted). The Java interpreter can execute Java bytecodes directly on any machine
`to which the interpreter and run-time system have been ported.
`
`Transmitting Structures (Object Serialization) [4, page 483][13, page 39]
`
`Object serialization, a new feature in Sun’s Java Development Kit version 1.1 (JDK1.1), is the ability to
`write the complete state of an object to an output stream, and then recreate that object at some later time by
`reading its serialized state from an input stream. Object serialization is of interest because it is common to
`read and write complex data in networking. An object can be serialized by passing it to the writeObject()
`method of the ObjectOutputStream class. Similarly, an object can be created from a serialized object
`
`6
`0008
`
`
`
`Java vs. C++ (contd.)
`
`stream by calling the readObject() method of the ObjectInputStream class and casting it to its correct type.
`Both these object stream types are part of the java.io package. Code required for sending an object from the
`client to a concurrent server is as follows:
`
`In the Client
`import java.io.*;
`import java.net.*;
`
`public class AtmApplet extends Applet
`{
`---
`initialization, networking etc.
`---
` int dacct = 111;
` int dpin = 1111;
` double dbal = 0.0;
` DataObject dob = new DataObject(dacct, dpin, dbal);
`
`
`
`// hard coded data values for this example
`
` ObjectOutputStream outter;
` ObjectInputStream inner;
` try {
` outter = new ObjectOutputStream(client.getOutputStream());
` inner = new ObjectInputStream(client.getInputStream());
`
` // sending data to Server
` outter.writeObject(dob);
` client.close();
` } catch ( IOException e ) { System.out.println(e);}
` }
`
`class DataObject implements Serializable
`{ public DataObject(int a, int p, double b)
` { dacct = a;
` dpin = p;
` dbal = b;
` }
`
` private int dacct, dpin;
` private double dbal;
`
`} T
`
`he server
`import java.io.*;
`import java.net.*;
`
`7
`0009
`
`class Server
`{ public static void main(String[] args)
` { ---
` NET INFORMATION
` }
`
`}c
`
`lass ServerHandler extends Thread
`{ ObjectOutputStream outter;
`
`
`
` ObjectInputStream inner;
`Java vs. C++ (contd.)
`
` public void run()
` { try
` { outter = new ObjectOutputStream(incoming_socket.getOutputStream());
` inner = new ObjectInputStream(incoming_socket.getInputStream());
` DataObject sdo = (DataObject)inner.readObject();
`} catch {catch(Exception e) {System.out.println(e);}}
`
`}
`
`} c
`
`lass DataObject imp lements Serializable
`{ public DataObject(int a, int p, double b)
` { dacct = a;
` dpin = p;
` dbal = b;
` }
` private int dacct, dpin;
` private double dbal;
`
`} I
`
`n C++, objects can be input and output using operator overloading. For object input, the stream-extraction
`operator >> is overloaded for the appropriate istream classes and for object output, the stream-extraction
`operator << is overloaded for the appropriate ostream classes. In each case, only the object’s data members
`are input or output in a form meaningful for objects of that particular abstract data type. When object data
`members are output, the object’s type information is lost in a way. However, if the program that is going to
`read this data knows what object type it corresponds to, then the data is simply read into objects of that
`type.
`
`Some other features of C++ and Java are described in the table below.
`
`Feature
`Program exit value
`
`Global variables
`
`Filenames
`
`Comments
`
`C++
`Main() can return a value
`
`Are allowed
`
`No such rule
`
`Two kinds
`/* */ block comment
`// single line comment
`
`Java
`Main() must be declared a void
`i.e. a value cannot be returned
`with a return statement. The only
`way to do so is to call
`System.exit()
`Are not allowed-every field or
`method is associated with classes
`and referred to by its fully
`qualified name. This care is taken
`to avoid conflicts
`Source file should have the same
`name as the public class in it
`Three kinds i.e.
`/* */ block comment
`// single line comment
`/** */ java doc comment
`The java doc comment is
`specially processed by the
`javadoc program to produce
`simple online documentation
`
`8
`0010
`
`
`
`Java vs. C++ (contd.)
`
`Feature
`Header files
`
`Primitive data types
`
`Creating Objects
`
`Accessing Objects
`
`Garbage collection
`
`Strings
`
`Synchronized statement
`
`Exception Handling
`
`Local variable declaration
`
`Java
`Does not have header files or
`function prototypes. A single
`Java™ object file serves as the
`interface definition and
`implementation for a class
`- Has specific byte and boolean
` types apart from the standard C
` types.
`- All variables have guaranteed
` default values i.e. boolean =
` false, byte = 0, int = 0
`- Boolean values are not integers
`- All integral types are signed
`
`Declaring a variable to hold an
`object does not create an object,
`objects are created using the new
`Keyword
`Fields in an object are accessed by
`using the dot notation
`
`There is no delete() or free() in
`Java - use is made of a technique
`called garbage collection to
`automatically detect objects or
`arrays no longer being used and to
`free them
`Strings are instances of the
`java.lang.String class. They are
`treated as primitive types – i.e. the
`String object is automatically
`created when a double quoted
`constant is seen. An operator +
`operates on String for
`concatenation
`Java provides the synchronized
`statement to protect multiple
`threads from modifying objects
`simultaneously. Methods and
`objects can also be synchronized
`Java requires that any method that
`can cause an exception(error) to
`occur must either catch it using the
`try/catch/finally statement or
`specify the type of exception with
`a throws clause in the method
`declaration
`Forward referencing allowed
`
`C++
`Declaration of member data and
`functions can be made in separate files
`
`- Does not have byte and boolean types
`
`- An un-initialized local variable
` usually has garbage as its value
`
`- Boolean values are integers
`- Integral types may be signed or
` unsigned
`C++ uses the new keyword to create
`objects dynamically
`
`Fields are accessed using the dot
`notation as well as -> or pointer
`notation (when pointer are used)
`Use of delete made to de-reference
`variables or objects created dynamically
`i.e. created using the new keyword
`
`Strings are null terminated character
`arrays
`
`Does not provide for a synchronized
`statement.
`
`C++ has exception handling but it is not
`mandatory
`
`Forward referencing not allowed
`
`9
`0011
`
`
`
`4.
`
`Communication between Client and Server using sockets
`
`Sockets were an innovation of Berkeley UNIX, version 4.3 BSD [2, page 11]. They allow the programmer
`to treat a network connection as another stream that bytes can be written onto or read from. Historically,
`sockets are an extension of one of UNIX’s ideas: that all I/O should look like file I/O to the programmers,
`whether they are working with a keyboard, a graphic display, a regular file, or a network connection.
`Sockets shield the programmer from low-level details of the network, like media types, packet sizes, packet
`retransmission, network addresses and more. A socket can perform the following basic operations:
`
`Connect to a remote machine
`
`Send data
`
`Receive data
`
`Close a connection
`
`Bind to a port
`
`Listen for incoming data
`
` Accept connections from remote machines on the bound port
`
`Assuming that we are using TCP for a connection oriented implementation, Java has two related classes
`that are required i.e. the Socket class and the ServerSocket class. The socket class is used by both the
`client and the server and has methods that correspond to the first four of these operations. The last three
`are only needed by the server and are implemented by the ServerSocket class. [6, page 149]
`
`Using sockets, communication can be established between the client and server in the following ways:
` In all the cases mentioned below, the server can make use of a database to retrieve or save data.
`
`4.1 Server application – Client application (Conventional method)
`
`In this method, both the server and the client is a Java application. The client application has to be
`loaded onto the client’s machine. The server can be concurrent i.e. serve more than one client at a time.
`The server and database lie on the server machine. The major disadvantage of this method, as already
`stated earlier, is that the software for the client has to be physically present on the client machine and the
`client machine has to have the Java interpreter to run it. If any changes are made to the client application,
`it has to be redistributed to the clients.
`
`User
`
`Client
`
`Server
`
` 1. User starts
` client
` User
`
` 2. Client contacts
` server
`Client Application
`
`Server Application
`
`4. Client displays
` result to user
`
` 3. Server sends
` reply
`
`A sample application using this method is attached (Appendix A)
`
`10
`0012
`
`
`
`4.2 Server application – Client web browser (using HTML and telnet)
`
`In this method, the server is a Java application and the client is a web browser like Netscape navigator. The
`user enters the URL/IP address of the server and is connected to HTTP daemon (HTTPD) web server on
`the server machine that loads the HTML file onto the client’s machine. This file provides part of the GUI
`and connects to the concurrent Java server using Java’s telnet applet. The advantage here is that the client’s
`machine only needs a web browser to be able to connect to the server. Moreover, any changes to the client
`can be made easily as the actual program lies on the server machine itself and is easily accessible by the
`administrator.
`
`User
`
`Client
`
` 1. User enters
` URL
` User
`
` 2. Browser
` contacts HTTDP
`
`Web browser
`
`Server
`
`HTTPD
`
` 3. HTTPD transfers
` the HTML with the
` embedded applet to
` the client machine
`
` 4. Telnet Applet
` establishes connection
`HTML + Telnet Applet
` with the server
`
`Server Application
`
` User
` 6. Client displays the
`result
`
` 5. Server serves the client
`
`A sample application is attached (Appendix B)
`
`11
`0013
`
`
`
`4.3 Server application – Client web browser (using HTML and Java applet)
`
`In this method the server is a Java application and the client is a Web browser like Netscape Navigator. The
`user enters the URL/IP address of the concurrent server and the HTTPD web browser loads the HTML file
`that has the Java applet embedded in it. The HTML file here is just a vehicle to transport the applet. The
`applet provides the complete GUI and opens a TCP/IP socket connection to the server on a designated port.
`The server may also be connected to a database (use of JDBC/ODBC bridge was made when implementing
`this method, this technique can also be used in the other methods described earlier)
`
`User
`
`Client
`
` 1. User enters
` URL
` User
`
` 2. Browser
` contacts HTTDP
`
`Web browser
`
`Server
`
`HTTPD
`
` 3. HTTPD transfers
` the HTML with the
` embedded applet to
` the client machine
`
` 4. Java Applet
`HTML + Java Applet
` establishes connection
` with the server
`
`Server Application
`
` 5. Server serves the client
`
` User
` 6. Client displays the
`result
`
`Also JDBC allows use of any ODBC database by the server i.e. anyone providing the server service can use
`their existing database if it is ODBC complaint.
`
`The advantage here is that the GUI is more user friendly. The applet allows restricted and relevant use only,
`an important security issue.
`
`A sample application is attached (Appendix C)
`
`12
`0014
`
`
`
`5. Sample Applications
`
`The following applications describe the different methods in which communication can be established
`between a client and server. These three versions follow the same basic concept, connection is established
`between the client and server using sockets and information is passed to and from them based on logic of
`the program. In all three versions, the server is a Java Application.
`
`Version 1
`
`Client Java Application
`In this simple program the client application uses the features of the java.net package to
`establishes a TCP/IP connection using sockets on a specified port with the server. The client
`and server open input and output streams over the socket using Java’s java.io package. The
`client sends a message to the server and the server acknowledges the message and closes the
`socket. (See Appendix A for program code.)
`
`Version 2
`
`Version 3
`
`Client HTML file, telnet applet and text database file
`This application involves an HTML program i.e. the bankatm.html. The user downloads the
`html file on his/her machine by using a web browser and giving the IP address of the machine
`where the concurrent server is running. The html establishes a TCP/IP connection with the
`server on a specified port using the telnet applet. The html file then sends requests like
`balance inquiry, request for deposit/withdrawal to the server using the output stream (java.io
`package). The server receives the request through its input stream, processes it and displays
`the result using its output stream. Once the user is finished he/she breaks connection by
`disconnecting. The server is also connected to a database file (a flat text file in this case). (See
`Appendix B for program code)
`
`Client HTML file, Java Applet and MS Access database file (using JDBC)
`This application involves a Java ATM applet and an HTML file. The user downloads the
`HTML file which has the java applet embedded in it, on his/her machine using a web browser
`and giving the IP address of the machine where the concurrent server is running. The applet
`starts executing and establishes TCP/IP socket connection with the server on a specified port
`using the java.net package. The applet then sends requests like balance inquiry to the server
`using the output stream (Java.io package). The server receives the request through its input
`stream, processes it and sends the result back to the client using its output stream. Once the
`user is finished, the socket connection between the client and server is closed. In this version,
`the server is connected to a database file (an MS Access file in this case) using the
`JDBC/ODBC driver. (See Appendix C for program code)
`
`13
`0015
`
`
`
`6. Some other methods of Communication between Client and Server
`
`6.1
`
`CGI Scripts [4, page 573]
`
`A CGI script is a simple protocol that can be used to communicate between HTML forms and a program. A
`CGI script can be written in any language that can read STDIN, write to STDOUT, and read environment
`variables, i.e. virtually any programming language, including C, Perl, or even shell scripting.
`
`In CGI scripting, a user fills out an HTML form and sends the text in the text fields and the setting of the
`check boxes and radio buttons to a CGI script on the server by clicking on the Submit button. CGI scripts
`are programs that reside on the server computer. Usually, there are many CGI scripts on a server. The
`HTML tag of the Submit button specifies the script to use to process that particular form. The HTTPD on
`the server launches the CGI script and feeds it the form data. The CGI script processes the form data and
`sends another HTML page back to the web browser who then displays the response page. CGI can be
`written in Java. This script is an application though and not an applet and will have to be launched by the
`HTTPD web server whenever a client submits a query naming that script as the processing agent.
`
`Data Flow during execution of a CGI script [4]
`
`User
`
`Client
`
`Server
`
` 1. User enters
` URL
`User
`
` 4. HTML form
` displayed to
`User
` User who
` fills the form
`
` User
` 9. Client displays the
`result
`
` 2. Browser
` contacts HTTDP
`
` 3. HTTPD transfers
` the HTML file to
` the client machine
`Web browser
`
`+
` 5.Client sends form data
` to HTTPD server
`
`HTML
`
`HTTPD
`Server
`
` 6. Server
` starts
` script
`
`CGI
`Script
`
` 8. HTTPD Server sends
` reply page
`