Chatting Report

65
INDEX 1. INTRODUCTION 1.1 PROBLEM STATEMENT: 1.2 OBJECTIVES: 1.3 SCOPE 2 Software Requirement Specifications 2.1 Platform Specification 2.2 Normal Requirements: 2.3 Functional Requirements: 2.4 Nonfunctional Requirements 3 Technology Used 3.1 Implementation Language 3.2 Rapid Code Generation in JAVA 3.3 Ease of Documentation and Maintenance in JAVA 3.4 Java Is Platform Independent 4 Use Case Diagrams 4.1 Use Case Model 4.2 Use Case Diagram. 5 System Flow Chart 5.1 Conceptual level Class Diagram. 5.2 Conceptual level Sequence diagram 5.3 Conceptual level Activity Diagram 6 E-R Diagrams 6.1 Activity Diagram 7 DESIGNS 7.1 Design Configuration 7..2 Design Technique 7.3 Data Design 1

Transcript of Chatting Report

Page 1: Chatting Report

INDEX

1. INTRODUCTION1.1 PROBLEM STATEMENT:1.2 OBJECTIVES:

1.3 SCOPE

2 Software Requirement Specifications2.1 Platform Specification2.2 Normal Requirements:2.3 Functional Requirements: 2.4 Nonfunctional Requirements

3 Technology Used 3.1 Implementation Language

3.2 Rapid Code Generation in JAVA 3.3 Ease of Documentation and Maintenance in JAVA 3.4 Java Is Platform Independent

4 Use Case Diagrams4.1 Use Case Model4.2 Use Case Diagram.

5 System Flow Chart5.1 Conceptual level Class Diagram.5.2 Conceptual level Sequence diagram5.3 Conceptual level Activity Diagram

6 E-R Diagrams 6.1 Activity Diagram

7 DESIGNS7.1 Design Configuration

7..2 Design Technique 7.3 Data Design

1

Page 2: Chatting Report

INDEX

8. Sample Coding

9. Output Screens

2

Page 3: Chatting Report

Project Profile

1. INTRODUCTION

Online chat can refer to any kind of communication over the Internet, but is primarily meant to refer to direct one-on-one chat or text-based group chat (formally also known as synchronous conferencing), using tools such as instant messengers, Internet Relay Chat, talkers and possibly MUDs. The expression online chat comes from the word chat which means "informal conversation".

3

Page 4: Chatting Report

1.1 PROBLEM STATEMENT:

Chatting software based loosely on IRC system. There is a central server handling all communications to and from clients. Each user can run the client program and connect to server to start chatting. All clients and server will have list of online users. List is updated as soon as the status of some client changes. There is one main chat room in which all messages can be seen by all clients. Users can also choose to chat in private with any one on the list. File transfer is available in private chat.

1.3 SCOPE

The various fields where this project can be used are as follows:

1. Software Development.2. Customer support System.3. Social Networking Sites.4. Distance learning

4

Page 5: Chatting Report

Software Requirement Specification

5

Page 6: Chatting Report

2.1 PLATFORM SPECIFICATION

From a number of tools used for designing of System software most important platform which we have used JAVA JDK as the working platform.

HARDWARE The system has been developed on an Intel \ Pentium III 1.5 GHz processor, 128 MB RAM ,Intel 810 Chipset, Seagate 20 GB hard disk and Monitor capable of displaying a maximum resolution of 1024 X 768 and a Logitech® mouse.

SOFTWARE The following software will be required for the development of the system:

Windows XP operating system.JDK 1.4MS-Word 2003 required for the generation of reports.

2.2 Normal Requirements:

These are the basic requirement that the project must provide.

Software requirement : JVM supporting Java 1.4 .

Hardware requirement :X86 Microprocessor, 64+ MB RAM.

2.3 Functional Requirements:

Functional requirement are used to express the behavior of a system by specifying both input & output condition that are expected to result.

Functional requirement is interaction between system and environment. It describes relationship between input & output of the system. Functional requirement specify which output should be produced from the given input. For each functional requirement, a detailed description of all the data inputs & there source, unit of measure, & the range of valid inputs must be specified.

For our project the functional requirement may be stated as follows:

2.4 Nonfunctional Requirements:

In order to deliver the desired quality to end user, a system must also exhibit a wide variety of attribute that are not described specifically by system’s functional

6

Page 7: Chatting Report

requirements. These requirements are called non-functional requirement like usability, reliability, performance, response time & supportability.

The nonfunctional requirements describe a restriction on the system that limits our choice for developing a solution to the problem.

The nonfunctional requirements in our project are:

Time

The project should be completed within the stipulated time period.

Cost

The cost involved in making the project should be less.

Usability

This requirement is present, As this system will interact with user

Reliability

This system must be highly robust

Performance

It should be fast enough to produce the output

7

Page 8: Chatting Report

Technology Used

TECHNOLOGY USED:

From a number of tools used for designing of system software most important platform, which we are using, is Java 2.0. Java Tools can be used for implementing various image

8

Page 9: Chatting Report

processing techniques. Java provides many inbuilt classes, which can be directly used for implementing the processing function and these classes also support hardware connectivity.The following software is used:(i). Operating System: -Windows XP onwards(ii). Front End: -Java higher version

3.1 IMPLEMENTATION LANGUAGE

We have used JAVA 2 as the implementation language. The Java language provides many language features that make it preferable to C or C++ for modern software development. On the top of this list is Java's intrinsic support for multi-threading, which is lacking in both C and C++. Other features are its exception-handling capabilities, which were recently introduced into C++; its strict adherence to class and object-oriented software development; and its automated garbage-collection support. In addition to these features, Java enforces a common programming style by removing the capability to slip outside the class- and object-oriented programming paradigm to develop C-style

function-oriented programs.

Standardization in JAVA

Although C and C++ have been standardized by the American National Standards Institute (ANSI), many C and C++ compilers provide custom enhancements to the language, usually through additional preprocessor directives.

Because these enhancements usually make their way into source code programs, a general lack of standardization results. Java does not yet suffer from any standardization problems because its syntax and semantics are controlled by a single organization.

The Java API

The predefined classes of the Java API provide a comprehensive platform-independent foundation for program development. These classes provide the capability to develop Windows and network programs that execute on a wide range of hosts. The Java I/O stream classes also provide a very useful set of filters for I/O processing. Whereas C and C++ may provide more extensive software libraries, none of these libraries provides as much platform-independent power as Java's API.

3.2 Rapid Code Generation in JAVA

9

Page 10: Chatting Report

Because Java is an interpreted language, it can be used to rapidly prototype applications that would require considerably more base software support in languages such as C or C++. The Java API also contributes to the capability to support rapid code generation. The classes of the Java API provide an integrated, easy-to-use repository for the development of application-specific software. Because the Java API provides high-level windows and networking Support, custom application prototypes can be constructed more quickly using these classes as a foundation.

3.3 Ease of Documentation and Maintenance in JAVA

Java software is essentially self-documenting when doc comments and the java doc tool are used to generate software documentation. The excellent Java API documentation is an example of the superior documentation capabilities provided by Java. Because Java software is inherently better structured and documented than C or C++ software, it is generally easier to maintain. In addition, the package orientation of Java software affords considerable modularity in software design, development, documentation, and maintenance.

Language used and its characteristics

Our project has been completely coded in JAVA, one of the most powerful programming languages.

Java is an Object-Oriented Programming Language developed by Sun Microsystems that plays to the strength of the Internet. Object-Oriented Programming (OOP) is an unusual, but powerful way to develop software. In OOP, a computer program is considered to be a group of objects that interact with each other.

The feature that is best known about Java is that it can be used to create programs that execute from World Wide Web pages. These programs are called Applets. A Java applet running on a Web page provides a much richer experience--both in terms of information and user interaction. Information can change in response to user input or be updated dynamically as a Web page is viewed.

Another design decision to make Java simpler is its elementary data types and objects. The language enforces very strict rules regarding variables--in almost all cases, you have to use variables as the data type they were declared to be, or use explicit casts to manipulate them. This arrangement permits mistakes in variable use to be caught when the program is compiled, rather than letting them creep into a running program where they're harder to find. As a result, programs behave in a more predictable manner.

“Java is just a small, simple, safe, object-oriented, interpreted or dynamically optimized, byte-coded, architecture-neutral, garbage-collected, multithreaded programming language

10

Page 11: Chatting Report

with a strongly typed exception-handling mechanism for writing distributed, dynamically extensible programs.”

A Java program is created as a text file with the file extension .java. It is compiled into one or the machine code instructions created when a computer program is compiled. The difference is that machine code must run on the computer system it was compiled for; byte codes can run on any computer system equipped to handle Java programs.

Characteristics of JAVA

The main features of Java which makes it such a widely used language across the globe are described as follows:

Java Is Small and Simple

However, Java has been described as "C++ minus" because of elements of C++ that were omitted. The most complex parts of C++ were excluded from Java, such as pointers and memory management. These elements are complicated to use, and are thus easy to use incorrectly. Finding a pointer error in a large program is an experience not unlike searching for the one-armed man who framed you for murder. Memory management occurs automatically in Java--programmers do not have to write their own garbage- collection routines to free up memory.

Another design decision to make Java simpler is its elementary data types and objects. The language enforces very strict rules regarding variables--in almost all cases, you have to use variables as the data type they were declared to be, or use explicit casts to manipulate them. This arrangement permits mistakes in variable use to be caught when the program is compiled, rather than letting them creep into a running program where they're harder to find. As a result, programs behave in a more predictable manner.

Java Is Object Oriented

Object-oriented programming (OOP) is a powerful way of organizing and developing software. The short-form description of OOP is that it organizes a program as a set of components called objects. These objects exist independently of each other, and they have rules for communicating with other objects and for telling those objects to do things. Think back to how Star7 devices were developed as a group of independent devices with methods for communicating with each other. Object-oriented programming is highly compatible with what the Green project was created to do and, by extension, for Java as well.

Java inherits its object-oriented concepts from C++ and other languages such as Smalltalk. The fact that a programming language is object oriented may not seem like a benefit to some. Object-oriented programming can be an intimidating subject to tackle, even if you have some experience programming with other languages. However, object-

11

Page 12: Chatting Report

oriented programs are more adaptable for use in other projects, easier to understand, and more bug proof.

The Java language includes a set of class libraries that provide basic variable types, system input and output capabilities, and other functions. It also includes classes to support networking, Internet protocols, and graphical user interface functions

3.4 Java Is Platform Independent

Platform independence is another way of saying that Java is architecture neutral. If both terms leave you saying "huh?," they basically mean that Java programs don't care what system they're running on.

Most computer software is developed for a specific operating system. Platform independence is the capability of the same program to work on different operating systems; Java is completely platform independent. A Java. class file of byte code instructions can execute on any platform without alteration.

AWT

The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include:

A rich set of user interface components;

A robust event-handling model;

Graphics and imaging tools, including shape, color, and font classes;

Layout managers, for flexible window layouts that don't depend on a particular window size or screen resolution.

Data transfer classes, for cut-and-paste through the native platform clipboard.

SWING:

Project Swing is the part of the Java Foundation Classes (JFC) software that implements a set of GUI components with a pluggable look and feel. Project Swing is implemented entirely in

12

Page 13: Chatting Report

the Java programming language, and is based on the JDKTM 1.1 Lightweight UI Framework. The pluggable look and feel lets you design a single set of GUI components that can automatically have the look and feel of any OS platform (Microsoft Windows, Solaris, Macintosh). Project Swing components include both 100% Pure Java certified versions of the existing AWT component set (Button, Scrollbar, Label, etc.), plus a rich set of higher-level components (such as tree view, list box, and tabbed panes

IO

Provides for system input and output through data streams, serialization and the file system. Unless otherwise noted, passing a null argument to a constructor or method in any class or interface in this package will cause a NullPointerException to be thrown.

3.5 CLASSES USED

JFrame

An extended version of java.awt.Frame that adds support for the JFC/Swing component architecture. The JFrame class is slightly incompatible with Frame. Like all other JFC/Swing top-level containers, a JFrame contains a JRootPane as its only child. The content pane provided by the root pane should, as a rule, contain all the non-menu components displayed by the JFrame. This is different from the AWT Frame case.

JPanel

Panel is the simplest container class. A panel provides space in which an application can attach any other component, including other panels

JMenuBar

An implementation of a menu bar. You add JMenu objects to the menu bar to construct a menu. When the user selects a JMenu object, its associated JPopupMenu is displayed, allowing the user to select one of the JMenuItems on it.

13

Page 14: Chatting Report

Use Case Diagram

4.1 Use Case Model

A use case is a description of a set of sequences of actions, including variants that a system performs to yield an observable result of value to an actor. It has various parts to the definition. A use case describes a set of sequences, in which each sequence represents the interaction of things outside the system (its actors) with the system itself (and its key abstractions). This behavior are in effect system-level functions that you use to visualize, specify, construct, and document the intended behavior of your system during requirements capture of your system as a whole. It involves the interaction of actors and the system. A use case carries out some tangible amount of work. Use case can be applied to the whole system, subsystem and even to individual classes and interfaces. They not

14

Page 15: Chatting Report

only represent the desired behavior but also the test cases for a particular element. Graphically, a use case is rendered as an ellipse. An actor represents a coherent set of roles that users of use cases play when interacting with use cases. Typically, an actor represents a role that a human, a hardware device, or even another system plays with a system.

A class is an abstraction of the things that are part of the vocabulary of the problem .it is not an individual object but rather represents a whole of objects thus a class is a description of a set of objects that share the same attributes operations relationships and semantics. Graphically a class is rendered as a rectangle. An attribute is a name property of a class that describes a range of values that instances of the property may hold. A class may have any number of attributes or no attributes at all it represents some property of the thing you are modeling that is shared by all objects of that class. An operation is the implementation of the service that can be requested from any object of the class to affect the behavior. In other words an operation is an abstraction of something you can do to an object and that is shared by all objects of that class. A responsibility is a contract or an obligation of a class when you create a class you are making a statement that all objects of that class have the same kind of state and the same kind of behavior these attributes and operations are just the features by which the class’s responsibilities are carried out.

Identification use cases and ActorsPrimary Actor: USERUse cases(i) Open Main Frame Window(ii) Open Server Window (iii) Open Client Window.(iv) Show List of Clients in Server window

Description of Use Cases.

4.2 Use Case Diagram.

Use case diagram shows a set of use cases and actors (a special kind of class and their relationships). Use case diagrams address the static use case view of a system, these diagrams are especially important in organizing and modeling the behaviors of a system.

v

15

Log Onto Chatline

Quit Chatline

Send Message to SINGLE

Send Control Message

Send Message to

ALL

Decode Chatter

Message<<include>><<include>>

Banned User

Chatline Manager

Internet Chatter

Start/Stop Chat ServerChatline

Manager<<include>>

<<generalizes>>

Use Cases diagram I

Page 16: Chatting Report

System Flow Chart

16

Page 17: Chatting Report

5.1 Conceptual level Class Diagram.

Diagram is a graphical representation of a set of elements most often rendered as a connected graph of vertices and arcs, UML includes following such diagrams.

A class diagram shows a set of classes, interfaces and collaborations and their relationships. These diagrams are most common diagram found in modeling object oriented systems. Class diagram address the static design view of a system. Class diagrams that include active classes address the static process view of a system.

The ChatServer class showing attributes and operations.

Conceptual

Specification

17

ChatServerComponent which will take all incoming connections and keep communication with chat clients active. Live Connection management will be monitored

ChatServer

receive connectionsmanage clientsenable communication

Page 18: Chatting Report

Implementation

18

ChatServernameChatter : Stringmessage : Stringconnections : CollectionsocketListener : SocketgetNewConnection()testConnection()timeOutConnection()disconnectUser()sendData()sendPrivate()receiveData()

Page 19: Chatting Report

5.2 Conceptual level Sequence diagram

An interaction diagram shows an interaction, consisting of a set of objects and their relationships, including the messages that may be dispatched among them. Interaction diagrams address the dynamic view of a system. Sequence diagramA sequence diagram is an interaction diagram that emphasizes the time ordering of messages.

5.3 Conceptual level Activity Diagram

It is a special kind of state chart diagram that shows the flow from activity to activity with in a system. Activity diagrams address the dynamic view of a system. They are especially important in modeling the function of a system and emphasize the flow of control among the objects.

19

Page 20: Chatting Report

20

ProjectAnalysis

InformationGathering

Study the Problem statement

Preparation Function specification

Selection of Process model

Performing the Requirement Analysis

Planning the project

Determine the Project Schedule

Analyze the Risks and make a Risk Management Strategy

Determine the Programming Language to be used.

Implementation

Chatting Server

Client

Private Chat

File Transfer

Testing of the system

Maintenance

Page 21: Chatting Report

DESIGN

21

Page 22: Chatting Report

Design is a meaningful engineering representation of something that is to be built. It can be traced to a customer’s requirements and at the same time assessed for quality against a set of predefined criteria for “good” design. Software engineers design computer-based systems but the skills required at each level of design work are different. At the data and architectural level, design focuses on patterns as they apply to the application to be built. At the interface level, human ergonomics often dictate our design approach. At the component level, a “programming approach” leads us to effective data and procedural designs. Design begins with the requirement model. Designers work to transform this model into four levels of design detail, the data structure, the system architecture, the interface representation and the component level detail. During each design activity, designer applies basic concepts and principles that lead to high quality. Ultimately, a design specification is produced. The specification is composed of the design models that describe data, architecture, interfaces and components. Each is a work product of the design process. At each stage, software design work products are reviewed for clarity, correctness, completeness and consistency with the requirements and with one another.

7.1 Design Configuration

Design concepts provide the software designer with a foundation from which more sophisticated design methods can be applied. Each design concept helps the software engineer to answer the following questions:

1. What criteria can be used to partition software into individual components?2. How is function or data structure detail separated from a conceptual representation of the software?What uniform criteria define the technical quality of a software design?The main design configurations are outlined below:

1. Abstraction: Abstraction permits one to concentrate on a problem at some level of generalization without regard to irrelevant low level details; use of abstraction also permits one to work with concepts and terms that are familiar in the problem environment without having to transform them to an unfamiliar structure.

2. Refinement: Stepwise refinement is a top-level design activity which involves developing a program by successively refining levels of procedural detail. In each step of the refinement, one or several instructions of the given program are decomposed into more detailed instruction until all the instructions are expressed in terms of any underlying computer or programming language.

3. Modularity: Modularity is a design concept in which the software is divided into separately named and addressable components, often called modules that are integrated to satisfy the problem requirements.

4. Software Architecture: Software architecture alludes to “the overall structure of the software and the ways in which that structure provides conceptual integrity for a system.”

22

Page 23: Chatting Report

It is the hierarchical structure of program components (modules), the manner in which those components interact and the structure of data that are used by the components.

5. Control Hierarchy: Also known as the program structure, the control hierarchy represents the organization of the program components (modules) and implies a hierarchy of control.

6. Structural Partitioning: Structural partitioning is the process of partitioning the program structure both horizontally and vertically. Horizontal partitioning involves defining separate branches of the modular hierarchy for each major program function. Vertical partitioning, on the hand, suggests that that control (decision making) and work should be distributed top-down in the program structure.

7. Data Structure: Data structure is a representation of the logical relationship among the individual elements of data. Data structure dictates the organization, methods of access, degree of associatively, and processing alternatives for information.

8. Software Procedure: The software procedure focuses on the processing details of each module individually and must provide a precise specification of processing including the sequence of events, exact decision points, repetitive operations, and even data organization and structure.

9. Information Hiding: The principle of information hiding states that the modules should be specified and designed so that information (procedures and data) contained within a module is inaccessible to other modules that have no need for such information.

There are two major phases to any design process: Diversification Convergence

Diversification is the acquisition of a repertoire of alternatives, the raw material of design: components, component solutions, and knowledge all contained in catalogs, textbooks, and the mind.

During convergence, the designer chooses and combines appropriate elements from this repertoire to meet the design objectives, as stated in the requirements documented as agreed to by the customer. The second phase is the gradual elimination of all but one particular configuration of components, and thus the creation of the final product.

7..2 Design Technique

The Requirement of the system has been analyzed and on the basis of

Customers need, we viewed the following methodologies:

23

Page 24: Chatting Report

(i) Procedural MethodologyIn the software engineering context, design focuses on four major areas of concern: data, architecture, interfaces and components. Data design is used for developing the design of various data structures.

(ii) Object Oriented MethodologyThere are three main objectives of the design phase:

(a) The analysis model is not sufficiently formal. In order to move seamlessly to the source code we must refine the objects; which operations should be offered, exactly what should be offered, exactly what should the communication between the different objects look like, which stimuli are sent, and so on.

(b) The actual system must be adapted to the implementation environment. In analysis we assumed an ideal world for our system. There is no ideal world, so in reality we must make adaptations to the environment in which the system is to be implemented.

(c) We want to validate the analysis results. If we discover points which are unclear in the analysis model or the requirements model, we must clarify them, perhaps by returning to the analysis process.

To develop the design model we perform three main steps:

(a) Identify the implementation environment. This step includes identifying and investigating the consequences that the implementation environment will have on the design. All strategic implementation decisions should be made.

(b) Incorporate these conclusions and develop a first approach to a design model. Here we use the analysis model as a base and translate the analysis objects into design objects in the design model that fit the current implementation environment.

(c) Describe how the objects interact in each specific use case. Here the design model is formalized to describe all stimuli sent between the objects and also to define what each operation will do to each object.

For the concrete use case we will draw an interaction diagram. The interaction diagram describes how each use case is offered by communicating objects. The diagram shows how the participating objects realize the use case through their interaction. The interaction takes place as the blocks send stimuli between one another. In the design model we refine the description of the use cases by showing in the interaction diagram how the objects behave in every specific use case. The interaction diagrams are controlled by events. A new event gives rise to a new operation. These events are stimuli that are sent from one object to another and initiate an operation. Interaction diagrams give the designer a unique ability to see the entire sequence in a use case at an overview level. The design model explicitly defines the interfaces of the objects and also the semantics of the objects. The design model will be composed of blocks which are design objects. These blocks will later be implemented as source codes. The implementation of blocks may be one of the specific classes or a group of class’s. Traceability is very important in object oriented design.

24

Page 25: Chatting Report

7.3 Data Design:

In our software the architecture of data design is data flow architecture. Data flow architecture is used when input data are to be transformed through a series of computational or manipulative components into output data. In our software the data given by the user passes through a series of transformations & depending upon this data & type of operation to be performed our image processing module tracks the operation and gives output. In our software user gives the input data to the GUI. The data from GUI is passed to the corresponding module, which checks the validity of input data. The correct data, which are the 2-D still images, are passed through the algorithms that are nothing but the filter programs. The output of the filter is sent to the display unit that converts this data into human readable form & the data is presented to the user.

Modeling Design is process through which requirements are translate into a blueprint for constructing the software. Initially the blueprint depicts a holistic view of software. That is, the design is represented at a high level of abstraction a level that can be directly traced a specific data, functional and behavior requirements. As design interaction occurs, subsequent refinement leads to design representations at much lower levels of abstraction. These can still be traced to can still be traced to requirement, but the connection, but the connection is stable.

25

Page 26: Chatting Report

Sample Coding

26

Page 27: Chatting Report

chatServer.java

package dukecomm.server;

import java.io.*;import java.net.*;import java.util.*;import javax.swing.*;

import dukecomm.protocols.*;

//MAIN CLASS THAT HANDLES THE CONNECTION REQUESTSpublic class ChatServer{

int serverPort;int serverLimit;ServerSocket server;

int onlineUsers;

//List of all client hadling threads in the server.SynchronizedVector handlers;

ServerInterface window;

//HANDLER FOR EACH INDIVIDUAL CLIENTpublic class ChatHandler implements Runnable{

protected ClientInfo clientInfo = new ClientInfo();

protected Socket socket;protected ObjectInputStream in;protected ObjectOutputStream out;

//Thread on which to run this handlerprotected Thread listener;

public ChatHandler( int clientID, Socket socket ){

clientInfo.clientId = clientID;this.socket = socket;//onlineUsers = 0;

}

27

Page 28: Chatting Report

//Set up parameters and required data with the clientprotected boolean handShake(){

try{

clientInfo.clientName = (String)in.readObject();

//If there are users on list and nick is not uniqueif( window.clientList.size()>0 &&

window.clientList.indexOf( clientInfo.clientName ) != -1 ){

try{

ConnectionNotice status = new ConnectionNotice();

status.status = false;out.writeObject( status );out.flush();socket.close();return false;

}catch( IOException w ){}

}

try{

ConnectionNotice status = new ConnectionNotice();

status.status = true;out.writeObject( status );

}catch( IOException w ){}

//Add client to list and send it the complete//client listwindow.clientList.addElement( clientInfo.clientName );out.writeObject( window.clientList );

//Tell all other clients about the new client//Construct an protocol object and broadcast itUpdateList newClient = new UpdateList();newClient.requestType = true;newClient.newClient = clientInfo.clientName;

28

Page 29: Chatting Report

broadcast( newClient );

onlineUsers++;}catch( Exception e ){}return true;

}

public synchronized void start(){

if ( listener == null ){

try{

//The order in whick these streams are created//is important. Reverse the order in client.out = new

ObjectOutputStream( socket.getOutputStream() );in = new

ObjectInputStream( socket.getInputStream() );

ConnectionNotice status = new ConnectionNotice();

if ( onlineUsers >= serverLimit ){

//server.window.taMessages.append(onlineUsers+" " + //ChatHandler client =

(ChatHandler)handlers.elementAt( onlineUsers-1 );try{

status.status = false;out.writeObject( status );out.flush();socket.close();return;

}catch( IOException w ){}

}

try{

status.status = true;

29

Page 30: Chatting Report

out.writeObject( status );}catch( IOException w ){}

if( !handShake() )return;

//Create a new thread and start listening to the clientlistener = new Thread( this );listener.start();

}

catch( IOException ignored ){}

}}

public synchronized void stop(){

if ( listener != null ){

//if ( listener != Thread.currentThread() )//{try{

listener.interrupt();listener = null;

//Remove handler from list.Remove client from active list

//Notify all other users that this client has left.handlers.removeElement( this );

window.clientList.removeElement( clientInfo.clientName );UpdateList newClient = new UpdateList();newClient.requestType = false;newClient.newClient = clientInfo.clientName;broadcast( newClient );

//Close the sockets and show message in server window

out.close();socket.close();window.enableKickOut( false );

30

Page 31: Chatting Report

window.taMessages.append( "Connection to client " + clientInfo.clientId + " closed...\n" );

}catch( IOException io_ex ){

JOptionPane.showMessageDialog( window, "Error closing connection to client", "Termination Error", JOptionPane.ERROR_MESSAGE );

}//}

}}

public void run(){

try{

handlers.addElement( this );

//Listen to input stream for messages from this clientwhile ( true ){

try{

Object clientMsg = in.readObject();

if( clientMsg instanceof Message ){

//If public message then broadcastif( ((Message)clientMsg).audience

== true ){

broadcast( clientMsg );}else //private message{

//To Locate the intended reciever.

//1) Get the id of recipient (recieverId)

//2) Get the reference of handler

//3) send message on its output stream

((ChatHandler)(handlers.elementAt(((Message)clientMsg).recieverId))).out.writeObject(clientMsg);

31

Page 32: Chatting Report

}}else if( clientMsg instanceof ChatRequest ){

//Tell the intended recipient that this//client wants to start a private chat//To Locate the intended reciever.//1) Get the id of recipient

(recieverId)//2) Get the reference of handler//3) send request on its output stream((ChatHandler)

(handlers.elementAt(((ChatRequest)clientMsg).recieverId))).out.writeObject(clientMsg);}else if( clientMsg instanceof

FileTransferMessage ){ ((ChatHandler)

(handlers.elementAt(((FileTransferMessage)clientMsg).recieverId))).out.writeObject(clientMsg);

}else if( clientMsg instanceof LogOut ){

//Reduce cont of active user and break out of the loop

onlineUsers--;break;

}else{

//If an unknown object is recievedSystem.out.println( clientMsg );

}}catch( ClassNotFoundException cnfe ){

JOptionPane.showMessageDialog( window, "Class of a serialized object cannot be found.", "Termination Error", JOptionPane.ERROR_MESSAGE );

break;}catch( InvalidClassException ice ){

JOptionPane.showMessageDialog( window, "Something is wrong with a class used by serialization.", "Termination Error", JOptionPane.ERROR_MESSAGE );

32

Page 33: Chatting Report

break;}catch( StreamCorruptedException sce ){

JOptionPane.showMessageDialog( window, "Control information in the stream is inconsistent.", "Termination Error", JOptionPane.ERROR_MESSAGE );

break;}catch( OptionalDataException ode ){

JOptionPane.showMessageDialog( window, "Primitive data was found in the stream instead of objects.", "Termination Error", JOptionPane.ERROR_MESSAGE );

break;}catch( IOException ioe){

//JOptionPane.showMessageDialog( null, "Any of the usual Input/Output related exceptions.", "Termination Error", JOptionPane.ERROR_MESSAGE );

break;}

}}catch ( Exception ignored ){}finally{

stop();}

}

//Broadcasts a message to all clientsprotected void broadcast( Object clientMsg ){

//Object streams have to be protectedsynchronized ( handlers ){

Enumeration enum = handlers.elements();

//Loop through all the clientswhile ( enum.hasMoreElements() ){

33

Page 34: Chatting Report

ChatHandler handler = ( ChatHandler ) enum.nextElement();

try{

handler.out.writeObject( clientMsg );out.flush();

}catch ( IOException ex ){

handler.stop();}

}}

}}

//Listen to connection requests from clientsprotected void listenForClients( ServerSocket server ){

window.taMessages.append( "Listening For Connections...\n\n" );

int clientID = 0;

while ( true ){

try{

//Listen to socket. When request recieved start//a handler and start listening againSocket client = server.accept();ChatHandler handler = new ChatHandler( ++clientID,

client );window.taMessages.append( "Connection accepted: "+

clientID + "\n" );handler.start();

}catch( IOException io_ex ){

JOptionPane.showMessageDialog( window,"Cannot Setup Connection","Client Connection Error",JOptionPane.ERROR_MESSAGE );

}}

}

protected void shutDown()

34

Page 35: Chatting Report

{Enumeration enum = handlers.elements();ServerShutDown shutdown = new ServerShutDown();

synchronized( handlers ){

//Close connection to all clients.Stop all handlerswhile ( enum.hasMoreElements() ){

try{

((ChatHandler)(handlers.firstElement())).out.writeObject(shutdown);

}catch( Exception e ){}

((ChatHandler)(handlers.firstElement())).stop();}

}System.exit(0);

}

//Save new configuration options to fileprotected synchronized void setConfiguration( int newPort , int newLimit ){

try{

FileWriter configFile = new FileWriter("serverConfig.cfg");//configFile.write( newPort );configFile.write( newPort + ";"+ newLimit+";" );//configFile.write( newLimit );configFile.close();serverLimit = newLimit;

}catch( IOException io_e ){

JOptionPane.showMessageDialog( window,"Cannot Save Configuration File","File Error",JOptionPane.ERROR_MESSAGE );

}}

protected synchronized void getConfiguration(){

try{

35

Page 36: Chatting Report

char[] buffer = new char[15];

FileReader configFile = new FileReader( "serverconfig.cfg" );

configFile.read( buffer );

//String[] temp = ( String.copyValueOf( buffer ) ).split(";");

String value = String.copyValueOf( buffer );String[] temp = value.split(";");

//system.out.println(temp[0]);//system.out.println(temp[1]);//serverPort = Integer.parseInt( temp[0] );serverPort = Integer.parseInt( temp[0] );//configFile.read( buffer );serverLimit = Integer.parseInt( temp[1] );configFile.close();

}catch( FileNotFoundException fnf_e ){

JOptionPane.showMessageDialog( null,"Configuration File Not Found, Using Defaults","Configuration File Missing",JOptionPane.ERROR_MESSAGE );

serverPort = 1665;serverLimit = 20;

}catch( IOException io_e ){

JOptionPane.showMessageDialog( null,"Error Reading Configuration File, Using Defaults","Configuration Error",JOptionPane.ERROR_MESSAGE );

serverPort = 1665;serverLimit = 20;

}}

ChatServer(){

getConfiguration();onlineUsers=0;try{

//Bind server on socket,show interface and listen for

36

Page 37: Chatting Report

//client connection requestsserver = new ServerSocket( serverPort );handlers = new Vector();window = new ServerInterface( this );listenForClients( server );

}catch( IOException io_e ){

JOptionPane.showMessageDialog( null,"Cannot Start Server","ServerSocket Error",JOptionPane.ERROR_MESSAGE );

System.exit(0);}finally{

try{

if( server != null )server.close();

}catch( IOException e ){}

}}

public static void main( String[] args ) throws IOException{

try{

UIManager.setLookAndFeel(new com.incors.plaf.kunststoff.KunststoffLookAndFeel());

//UIManager.setLookAndFeel(new com.birosoft.liquid.LiquidLookAndFeel());

//UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );//UIManager.setLookAndFeel(new

se.diod.hippo.plaf.HippoLookAndFeel());//UIManager.setLookAndFeel( new

it.unitn.ing.swing.plaf.macos.MacOSLookAndFeel());}catch( UnsupportedLookAndFeelException ex ){}

new ChatServer();}

37

Page 38: Chatting Report

}

38

Page 39: Chatting Report

Output Screens

39

Page 40: Chatting Report

Snapshot of Server Window

Snapshot of Server configuration window

40

Page 41: Chatting Report

Snapshot of Client

Snapshot of Client Login

41

Page 42: Chatting Report

LIMITATION

42

Page 43: Chatting Report

The Limitations of the project, which we have found during the testing of this project, are as follows:

1. In private chatting only two clients can communicate.2. There is only one chat room.3. This not provides secure chatting.

43

Page 44: Chatting Report

FUTURE ENHANCEMENT

44

Page 45: Chatting Report

Possible extension can be as follows:

1) Secure Chatting 2) Private Chat rooms3) Detect chat robots and Block them4) Audio/Video Chatting

45

Page 46: Chatting Report

CONCLUSION

46

Page 47: Chatting Report

Our software consists of three main modules:

Chat Server: Server Program run on high performance computer to act as server for all the clients.

Chat Client: Client Program run on any machine which have JRE installed and wants to participate in chatting.

47

Page 48: Chatting Report

Bibliography&

References

48

Page 49: Chatting Report

Bibliography & References

8.1 Reference Books

Java References:

1) Beginning Java2 by Ivor Horton

2) The complete Reference, Java2, Naughton and Schildt

3) Core Java part 1 & 2 from Sunsoft Press

4) Digital Image Processing – Rafeal C. Gonzalez & Richard E. Woods.

5) Digital Image Processing using Java – Nick Efford

6) Image Processing, analysis, and machine vision (2nd edition)- Milan

Sonka, Vaclav Hlavac & Roger Boyle.

Report References:

1) Software Engineering – A Practitioner’s Approach - Roger S. Pressman

8.2 Other Documentation and Resources

Websites:

http://www.java.sun.com

The Java Tutorial

49