chat server report

61
CHAT SERVER ABOUT PROJECT About Project: The project is CHAT SERVER. This project is made for any organization with basic LAN facilities . This project is step forward towards managing the information transfer in an organization in an efficient and secure manner .The system aims to provide LAN based intra-office communication. In the current scenario of today’s business, with neck breaking competition, an organization requires to be up- to-date in the technological field. A well designed and easy-to-use communication system will certainly give the organization an edge over the other organizations with outdated and manual communication system, with manpower doing the bulk of data transfer in the form of files and paper documents. With advanced features like e-mail, chat, message broadcast, server side authentication, multimedia data transfer, message printout facility, this software turns out to be a very suitable one for any type of organization which requires an efficient and secure communication among their employees. 1

Upload: akshay-dagar

Post on 02-Dec-2014

133 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Chat Server Report

CHAT SERVER

ABOUT PROJECT

About Project:

The project is CHAT SERVER. This project is made for any organization with basic

LAN facilities . This project is step forward towards managing the information

transfer in an organization in an efficient and secure manner .The system aims to

provide LAN based intra-office communication.

In the current scenario of today’s business, with neck breaking competition, an

organization requires to be up-to-date in the technological field. A well designed and

easy-to-use communication system will certainly give the organization an edge over

the other organizations with outdated and manual communication system, with

manpower doing the bulk of data transfer in the form of files and paper documents.

With advanced features like e-mail, chat, message broadcast, server side

authentication, multimedia data transfer, message printout facility, this software turns

out to be a very suitable one for any type of organization which requires an efficient

and secure communication among their employees.

Knowledge domain used to develop the system:

The operating system used is Windows XP. The software tools required by this project

are JAVA, MS ACCESS.

The project requires the knowledge of the following subjects:

Software Language: JAVA (Swings, JDBC, Threads and object serialization)

Database: MS ACCESS

Database handling: SQL

This project is carried out under the guidance of Er. Jasdeep Kaur (lecturer in

computer science dept. B.B.S.B.E.C. FATEHGARH SAHIB) .

1

Page 2: Chat Server Report

CHAT SERVER

Potential users:

Employees at all levels of hierarchy in an organization , that is, production

team , managers, accounts, finance, HR staff, CEOs, etc.

In educational institutions, with the users being the staff members, HODs,

Principal, etc.

In government undertakings, to replace the existing manual system, which is highly

inefficient.

2

Page 3: Chat Server Report

CHAT SERVER

Profile of Problem

The software aims at automating the existing manual systems and providing secure,

cheaper and quicker communication within an organization. As this is a well designed

and easy-to-use communication system will certainly give the organization an edge

over the other organizations with outdated and manual communication system, with

manpower doing the bulk of data transfer in the form of files and paper documents.

With advanced features like e-mail, chat, message broadcast, server side

authentication, multimedia data transfer, message printout facility, this software turns

out to be a very suitable one for any type of organization which requires an efficient

and secure communication among their employees. It provides centralized

information transfer system with any number of client systems, to cater to any number

of users. The project gives the user an easy-to-use graphical interface that can be

easily used by a novice.

Features of proposed project are as follow:

Automation of existing manual information systems.

Reduction of manual processing

Keep track of daily information exchange at the server by the administrator.

Increase in processing and transfer speeds of information over the network.

Reduction of errors and viruses due to non requirement of the internet.

Keeping track that message should be delivered at the correct destination.

Fast retrieval of all type of information

3

Page 4: Chat Server Report

CHAT SERVER

OBJECTIVES

The software aims at automating the existing manual systems and providing secure,

cheaper and quicker communication within an organization. As this is a well designed

and easy-to-use communication system will certainly give the organization an edge

over the other organizations with outdated and manual communication system, with

manpower doing the bulk of data transfer in the form of files and paper documents.

With advanced features like e-mail, chat, message broadcast, server side

authentication, multimedia data transfer, message printout facility, this software turns

out to be a very suitable one for any type of organization which requires an efficient

and secure communication among their employees. It provides centralized information

transfer system with any number of client systems, to cater to any number of users.

The project gives the user an easy-to-use graphical interface that can be easily used by

a novice.

The Main objectives of this project are:

Reduction of paper work

Automation of existing manual information systems.

Reduction of manual processing

Keep track of daily information exchange at the server by the administrator.

Increase in processing and transfer speeds of information over the network.

Decrease in processing time

Reduction of errors and viruses due to absence of internet

Keeping track that message should be delivered at the correct destination.

Fast retrieval of all type of information

Good efficiency and response time

More consistent data handling

A user-friendly system which do not require any special training or expertise of

computer

4

Page 5: Chat Server Report

CHAT SERVER

EXISTING Vs PROPOSED SYSTEM

The project CHAT SERVER is step forward towards managing the information

transfer in an organization in an efficient and secure manner .The system aims to

provide LAN based intra-office communication. As the existing communication

system requires internet access, that is, it is prone to viruses and insecure information

due to interaction with outside world through the net. Moreover, the cost of internet

connections are cut as the proposed system utilizes LAN.

The proposed system will increase the processing of purchase and supply of wheat in

various district of Punjab. This will keep track of quantity of wheat purchased at price

lower than fixed MSP by the centre Government and will specify the reasons for such

purchase. This will result in faster retrieval of all type of information and will provide

user-friendly system which do not require any special training or expertise of

computer

5

Page 6: Chat Server Report

CHAT SERVER

SYSTEM REQUIREMENTS

Product Definition

The CHAT SERVER is a computerized LAN based intra-office communication

system . As the existing communication systems requires internet

access, that is, it is prone to viruses and insecure information due to interaction with

outside world through the net. Moreover, the cost of internet connections are cut as the

proposed system utilizes LAN. This would also replace the outdated manual

communication system.

This will result in faster retrieval of all type of information and will provide user-

friendly system which do not require any special training or expertise of computer

The main features of this package are:

The basic e-mail features.

Message Broadcast facility.

Multimedia Data Transfer.

Chat.

Printout feature.

Server side user authentication

Processing Environment:

The programming language and development tools are the critical factors in the

functioning of the developed system, so proper attention has to be paid while selecting

these tools. Following are the minimum requirements for installation and making use

of the software package:

6

Page 7: Chat Server Report

CHAT SERVER

Hardware requirements:

Processor: Pentium

RAM: 128MB

HARD DISK: 40GB

Printer: Any compatible printer

Software requirements:

JDK 1.5

MS ACCESS

JAVA being the platform independent language to generate the user-friendly Software

system is used as Front-end system and MS ACCESS as Back-end database system,

this will facilitate user in operating the system successfully.

A platform is the hardware or software environment in which a program runs. We've

already mentioned some of the most popular platforms like Windows 2000/XP, Linux,

Solaris, and Mac OS. Most platforms can be described as a combination of the

operating system and hardware. The Java platform differs from most other platforms

in that it's a software-only platform that runs on top of other hardware-based

platforms.

The Java platform has two components:

The Java Virtual Machine (Java VM)

The Java Application Programming Interface (Java API)

Feasibility Analysis

Feasibility study describes and evaluates candidate systems and provides for the

selection of the best candidate system that meets the system performance

requirements. Three key considerations are involved in the feasibility analysis:

7

Page 8: Chat Server Report

CHAT SERVER

1. Economic feasibility

2. Technical

3. Behavioral

1. Economic Feasibility

Economic feasibility determines the benefits and saving that are expected from the

system and compare them with costs. Cost/Benefit analysis has been done on the basis

of total cost of the system and direct and indirect benefits derived from the system.

The total cost for the proposed system comprises of hardware costs and software

costs. The main aim of economic feasibility is to check whether the system is

financially affordable or not. The cost for the proposed system can be divided into two

parts given below:

Hardware Costs

The hardware cost for the proposed system can be calculated from cost of hardware

needed for the development of the proposed system. The hardware specifications for

the system are given below:

Personal Computer: The cost of the PC depends upon the configuration of the

PC. The minimum specification assumed for the Pc is given below:

Pentium IV processor

128 MB RAM

40 GB free disk space

MS Windows

Any compatible printer

Server: As the software is a client-server based application, thus an efficient

server would act as the backbone of a good communication system. The minimum

specifications are:

Pentium IV processor

256 MB RAM

8

Page 9: Chat Server Report

CHAT SERVER

120 GB free disk space

MS Windows

Software Costs: the Software costs for the proposed system can be calculated from

the cost of software tools needed from the development of the proposed system. The

software tools needed for the development of the system are given below:-

JDK 1.5

MS ACCESS

2. Technical Feasibility

Technical Feasibility centers on the existing system and to what extent it can support

the proposed system. In this part of feasibility analysis we determined the technical

possibilities for the implementation of the system. Two major benefits are:

Improving the performance

Minimizing the cost of processing

The performance category emphasis improvements in the accuracy and access to the

information.It also makes easier to access the system by the authorized users.

3. Behavioral Feasibility:

Behavioral feasibility estimates the reaction of the User staff towards the development

of the computerized system. For the successful implementation of any system, the

users must be impressed that the new system is for his benefit. So, the behavioral

feasibility plays a very important role in the development of new system It reveals that

whether the system is acceptable by user or not. If the user does not ready to use it,

then it doesn’t matter how best the system is or how much effort you are putting in its

development.

9

Page 10: Chat Server Report

CHAT SERVER

Project Plan

One has been assigned the task of gathering required information related to the

proposed project and also assigned the task of studying the existing system. After the

completion of task various disadvantages of existing project has been studied and will

be kept in mind for the designing of proposed project.

2nd person has been assigned the task of interface design and design of various

databases to be used by the proposed project. After the completion of task MS

ACCESS has been chosen as the database required for database connectivity with

JAVA.

3rd person has been assigned the task of design and coding which is completed up to

mark.

The various other tasks are performed collectively by the team members, which

involves the team cooperation.

Development Schedule:

System development revolves around a life cycle that begins with the recognition of

user needs. Following a feasibility study, the key stages of cycle are evaluation of

present system, information gathering, cost/benefit analysis, detailed design and

implementation of candidate system. The life cycle is not a procedure that deals with

hardware and software. It is a building computer-based system to help the user to

operate system effectively and manage the information successfully. The development

schedule as above was followed within a fixed timeframe of six months.

Programming Languages and Development tools:

10

Page 11: Chat Server Report

CHAT SERVER

The programming language and development tools are the critical factors in the

functioning of the developed system, so proper attention has to be paid while selecting

these tools. Following are the minimum requirements for installation and making use

of the software package:

Software requirements:

JAVA Developer Toolkit 1.5

MS ACCESS

Windows/ Linux platform

JAVA being the platform independent language to generate the user-friendly Software

system is used as Front-end system and MS ACCESS as Back-end database system,

this will facilitate user in operating the system successfully.

About the Java Technology

Java technology is both a programming language and a platform.

The Java Programming Language

The Java programming language is a high-level language that can be characterized by

all of the following buzzwords:

Simple Architecture neutral

Object oriented Portable

Distributed High performance

Interpreted Multithreaded

Robust Dynamic

Secure

11

Page 12: Chat Server Report

CHAT SERVER

With most programming languages, you either compile or interpret a program so that

you can run it on your computer. The Java programming language is unusual in that a

program is both compiled and interpreted. With the compiler, first you translate a

program into an intermediate language called Java bytecodes —the platform-

independent codes interpreted by the interpreter on the Java platform. The interpreter

parses and runs each Java bytecode instruction on the computer. Compilation happens

just once; interpretation occurs each time the program is executed.

You can think of Java bytecodes as the machine code instructions for the Java Virtual

Machine (Java VM). Every Java interpreter, whether it's a development tool or a Web

browser that can run applets, is an implementation of the Java VM.

Java bytecodes help make "write once, run anywhere" possible. You can compile your

program into bytecodes on any platform that has a Java compiler. The bytecodes can

then be run on any implementation of the Java VM. That means that as long as a

computer has a Java VM, the same program written in the Java programming

language can run on Windows 2000, a Solaris workstation.

The Java Platform

A platform is the hardware or software environment in which a program runs. We've

already mentioned some of the most popular platforms like Windows 2000, Linux,

Solaris, and MacOS. Most platforms can be described as a combination of the

operating system and hardware. The Java platform differs from most other platforms

in that it's a software-only platform that runs on top of other hardware-based

platforms.

The Java platform has two components:

12

Page 13: Chat Server Report

CHAT SERVER

The Java Virtual Machine (Java VM)

The Java Application Programming Interface (Java API)

You've already been introduced to the Java VM. It's the base for the Java platform and

is ported onto various hardware-based platforms.

The Java API is a large collection of ready-made software components that provide

many useful capabilities, such as graphical user interface (GUI) widgets. The Java

API is grouped into libraries of related classes and interfaces; these libraries are

known as packages. The next section highlights what functionality some of the

packages in the Java API provide.

The following figure depicts a program that's running on the Java platform. As the

figure shows, the Java API and the virtual machine insulate the program from the

hardware.

Native code is code that after you compile it, the compiled code runs on a specific

hardware platform. As a platform-independent environment, the Java platform can be

a bit slower than native code. However, smart compilers, well-tuned interpreters, and

just-in-time bytecode compilers can bring performance close to that of native code

without threatening portability.

What Can Java Technology Do?

The most common types of programs written in the Java programming language are

applets and applications. If you've surfed the Web, you're probably already familiar

with applets. An applet is a program that adheres to certain conventions that allow it to

run within a Java-enabled browser.

However, the Java programming language is not just for writing cute, entertaining

applets for the Web. The general-purpose, high-level Java programming language is

13

Page 14: Chat Server Report

CHAT SERVER

also a powerful software platform. Using the generous API, you can write many types

of programs.

An application is a standalone program that runs directly on the Java platform. A

special kind of application known as a server serves and supports clients on a

network. Examples of servers are Web servers, proxy servers, mail servers, and print

servers. Another specialized program is a servlet. A servlet can almost be thought of

as an applet that runs on the server side. Java Servlets are a popular choice for

building interactive web applications, replacing the use of CGI scripts. Servlets are

similar to applets in that they are runtime extensions of applications. Instead of

working in browsers, though, servlets run within Java Web servers, configuring or

tailoring the server.

How does the API support all these kinds of programs? It does so with packages of

software components that provides a wide range of functionality. Every full

implementation of the Java platform gives you the following features:

The essentials: Objects, strings, threads, numbers, input and output,

data structures, system properties, date and time, and so on.

Applets: The set of conventions used by applets.

Networking: URLs, TCP (Transmission Control Protocol), UDP (User

Datagram Protocol) sockets, and IP (Internet Protocol) addresses.

Internationalization: Help for writing programs that can be localized

for users worldwide. Programs can automatically adapt to specific

locales and be displayed in the appropriate language.

Security: Both low level and high level, including electronic signatures,

public and private key management, access control, and certificates.

Software components: Known as JavaBeansTM, can plug into existing

component architectures.

Object serialization: Allows lightweight persistence and

communication via Remote Method Invocation (RMI).

14

Page 15: Chat Server Report

CHAT SERVER

Java Database Connectivity (JDBCTM): Provides uniform access to a

wide range of relational databases.

Features of JAVA Technology

Get started quickly: Although the Java programming language is a

powerful object-oriented language, it's easy to learn, especially for

programmers already familiar with C or C++.

Write less code: Comparisons of program metrics (class counts, method

counts, and so on) suggest that a program written in the Java

programming language can be four times smaller than the same program

in C++.

Write better code: The Java programming language encourages good

coding practices, and its garbage collection helps you avoid memory

leaks. Its object orientation, its JavaBeans component architecture, and

its wide-ranging, easily extendible API let you reuse other people's

tested code and introduce fewer bugs.

Develop programs more quickly: Your development time may be as

much as twice as fast versus writing the same program in C++. Why?

You write fewer lines of code and it is a simpler programming language

than C++.

Avoid platform dependencies with 100% Pure Java: You can keep

your program portable by avoiding the use of libraries written in other

languages. The 100% pure JAVA is a repository of historical process

manuals, white papers, brochures, and similar materials online.

Write once, run anywhere: Because 100% Pure Java programs are

compiled into machine-independent bytecodes, they run consistently on

any Java platform.

Distribute software more easily: You can upgrade applets easily from

a central server. Applets take advantage of the feature of allowing new

15

Page 16: Chat Server Report

CHAT SERVER

classes to be loaded "on the fly," without recompiling the entire

program.

SYSTEM REQUIREMENT SPECIFICATIONS

Developing Environment:

The development environment is the critical factor in the functioning of the developed

system, so proper attention has to be paid while selecting this environment. Following

are the tools, which are used in developing software package:

16

Page 17: Chat Server Report

CHAT SERVER

Operating Environments:

The proposed project will operate under the following specification

Hardware Required:

Processor: Pentium Processor

RAM: 128MB

HARD DISK: 40GB

Printer: Any compatible printer

Software Required:

O.S.: Window 98, 2000, XP, Linux

Language: JAVA

Design Phase

The High Level Design

In this phase, we have decided how the application should function. The formats for

data input and data output re finalized here. The functional specifications

17

Page 18: Chat Server Report

CHAT SERVER

documentation of the application is presented in a language that can be understood all.

The finished project design is, however, executed on the approval.

We have identifies the following interfaces which are required for the project to

function efficiently.

Server side Front-end for creating/deleting user accounts

Login screen

18

Page 19: Chat Server Report

CHAT SERVER

This interface is used for accepting username and password and allow authenticated

users to move further. It also allows the users to change their passwords.

Access Denied message screen

When an unauthorized user tries to log-in to the system, this message is displayed.

19

Page 20: Chat Server Report

CHAT SERVER

The Low Level Design

In this phase, a detailed design of software modules, based on the high level design, is

created. In addition, we have also created specifications for the various software

modules of an application. We have also decided on a number of Java classes, names

of these classes, and other such details for the project.

20

Page 21: Chat Server Report

CHAT SERVER

The Testing Phase

Testing is vital to the success of the system. System testing makes a logical

assumption that if all the parts of the systems are correct, the goal will be successfully

achieved. Inadequate testing leads to errors that may not appear until months later.

This creates two problems:

The time lag between the cause and the appearance of the problem

The effect of system errors on files and records within the system

A small system error can conceivably explode into a much larger problem. Effective

testing early in the process translates directly into long-term cost savings from a

reduced number of errors.

Another reason for system testing is its utility as a user-oriented vehicle before

implementation. The best program is worthless if it does not meet the user needs.

Unfortunately, the user’s demands are often compromised by efforts to facilitate

program or design efficiency in terms of processing time or memory utilization. Often

the computer technician and the user have communication barriers due to different

backgrounds, interests, priorities and perhaps languages. The system tester (designer,

programmer or user) who has developed some computer mastery can bridge this

barrier

Testing Techniques

Both the Black Box testing and White Box testing techniques will be applied to the

proposed project for validating the software interface and to selectively ensure that the

internal working of the software is correct. The input will be validated so that the

correct output is produced. The checks for consistence of the database will be properly

evaluated. The procedure of the system will be highly checked for the logical paths

and for specific set of conditions, loops etc.

21

Page 22: Chat Server Report

CHAT SERVER

1. All the paths within module will be exercised at least once

2. The logical decision will be exercised for true or false sides

3. Whole code will be verified for the syntax errors

4. The internal data structure will be validated for data consistency

5. The graphical user interface will be checked for particular event

6. The complete application will be tested after the integration of all modules and

sub modules

Testing Strategies

Unit testing will be applied to all the modules of the project. All the modules of the

project will be tested with White Box and Black Box testing to complete unit testing.

Integration Testing will also be applied to verify that all the interfaces work in co-

ordination with each other. The Data Flow between different modules will be verified

for the consistency of the system. The Bottom Up approach of integration will be

applied to the proposed project. The alpha testing of the project has been done by the

team members. The beta testing will be done by the employees of Food and Supply

Department

Sample Data

The sample data will be prepared to ensure the proper working of the software and

validate each module. After testing the proposed project with this sample data the

expected results will be compared with the outputs obtained and thereafter further

steps will be taken if necessary

22

Page 23: Chat Server Report

CHAT SERVER

IMPLEMENTATION/CONVERSION PLAN

Conversion means changing from one system to another. The objective is to put the

tested system into operation while holding costs, risks and personal irritation to a

minimum. It involves:

1. Installing terminals

2. Installing the appropriate hardware and software

3. Creating computer compatible files

4. Training the operating staff

The conversion plan involves the following steps:

Conversion begins with the review of the project plan, the system test documentation,

and the implementation plan. The parties involved are the user, the project team and

the operators.

1. The conversion portions of the implementation plan to be finalized and

approved.

2. Files are converted

3. Parallel processing between the existing and the new systems to be initiated

4. Results of computer operations of the new system to be logged

5. Assuming no problems, parallel processing to be discontinued

6. Implementation results to be documented

7. After all these steps, conversion is complete and the new system will be now

officially operational

23

Page 24: Chat Server Report

CHAT SERVER

Procedure for Implementation

24

System TestDocumentation

ImplementationPlan

Conversion portion ofImplementation plan

Perform fileConversion

Project Plan

Log results of Conversion

AnyDiscrepancies?

Diagnose and Correct discrepancies

Discontinue parallel processing

Complete conversion

Implementation documentation

Implementation results

Project Plan

Perform parallel processing

Prepare plan for post-implementation

Page 25: Chat Server Report

CHAT SERVER

CODING

25

Page 26: Chat Server Report

CHAT SERVER

1. Login.java

/

********************************************************

********

*

* Description

* This is a Login frame of client side application in chat System.

* It is used to just take the user name

*

* Remarks

* Before running the Login application make sure the server is

running.

* If server is running then only you can execute your application.

********************************************************

**********/

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import java.util.*;

// Login class which takes a user name and passed it to client class

public class Login implements ActionListener{

JFrame frame1;

26

Page 27: Chat Server Report

CHAT SERVER

JTextField tf;

JButton button;

JLabel heading;

JLabel label;

public static void main(String[] args){

new Login();

}

public Login(){

frame1 = new JFrame("Login Page");

tf=new JTextField();

button=new JButton("Login");

heading=new JLabel("Chat Server");

heading.setFont(new Font("Impact", Font.BOLD,40));

label=new JLabel("Enter you Login Name");

label.setFont(new Font("Serif", Font.PLAIN, 24));

JPanel panel = new JPanel();

button.addActionListener(this);

panel.add(heading);panel.add(tf);panel.add(label);

panel.add(button);

heading.setBounds(30,20,280,80);

label.setBounds(20,100,250,60);

tf.setBounds(50,150,150,30);

button.setBounds(70,200,90,30);

frame1.getContentPane().add(panel);

27

Page 28: Chat Server Report

CHAT SERVER

panel.setLayout(null);

frame1.setSize(300, 300);

frame1.setVisible(true);

frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

// pass the user name to MyClient class

public void actionPerformed(ActionEvent e){

String name="";

try{

name=tf.getText();

frame1.dispose();

MyClient mc=new MyClient(name);

}catch (IOException te){}

}

}

2. MyClient.java

/

********************************************************

********

*

* Description

* This is a client side of chat application.

28

Page 29: Chat Server Report

CHAT SERVER

* This application is used to sending and receiving the messages

* and in this we can maintain the list of all online users

*

* Remarks

* Before running the client application make sure the server is

* running.If server is running then only you can execute your

* application.

********************************************************

**********/

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import java.net.*;

import java.util.ArrayList;

import java.util.Iterator;

//create the GUI of the client side

public class MyClient extends WindowAdapter implements

ActionListener{

JFrame frame;

JList list;

JList list1;

JTextField tf;

29

Page 30: Chat Server Report

CHAT SERVER

DefaultListModel model;

DefaultListModel model1;

JButton button;

JButton lout;

JScrollPane scrollpane;

JScrollPane scrollpane1;

JLabel label;

Socket s,s1,s2;

DataInputStream din;

DataOutputStream dout;

DataOutputStream dlout;

DataOutputStream dout1;

DataInputStream din1;

String name;

MyClient(String name)throws IOException{

frame = new JFrame("Client Side");

tf=new JTextField();

model=new DefaultListModel();

model1=new DefaultListModel();

label=new JLabel("Message");

list=new JList(model);

list1=new JList(model1);

button=new JButton("Send");

30

Page 31: Chat Server Report

CHAT SERVER

lout=new JButton("Logout");

scrollpane=new JScrollPane(list);

scrollpane1=new JScrollPane(list1);

JPanel panel = new JPanel();

button.addActionListener(this);

lout.addActionListener(this);

panel.add(tf);panel.add(button);panel.add(scrollpane);

panel.add(label);panel.add(lout);

panel.add(scrollpane1);

scrollpane.setBounds(10,20,180,150);

scrollpane1.setBounds(250,20,100,150);

label.setBounds(20,180,80,30);

tf.setBounds(100,180,140,30);

button.setBounds(260,180,90,30);

lout.setBounds(260,230,90,30);

frame.getContentPane().add(panel);

panel.setLayout(null);

frame.setSize(400, 400);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.name=name;

frame.addWindowListener(this);

s=new Socket("localhost",1004); //creates a socket object

31

Page 32: Chat Server Report

CHAT SERVER

s1=new Socket("localhost",1004);

s2=new Socket("localhost",1004);

//create inputstream for a particular socket

din=new DataInputStream(s.getInputStream());

//create outputstream

dout=new DataOutputStream(s.getOutputStream());

//sending a message for login

dout.writeUTF(name+" has Logged in");

dlout=new DataOutputStream(s1.getOutputStream());

dout1=new DataOutputStream(s2.getOutputStream());

din1=new DataInputStream(s2.getInputStream());

// creating a thread for maintaning the list of user name

My1 m1=new My1(dout1,model1,name,din1);

Thread t1=new Thread(m1);

t1.start();

//creating a thread for receiving a messages

My m=new My(din,model);

Thread t=new Thread(m);

t.start();

}

public void actionPerformed(ActionEvent e){

// sending the messages

if(e.getSource()==button){

32

Page 33: Chat Server Report

CHAT SERVER

String str="";

str=tf.getText();

tf.setText("");

str=name+": > "+str;

try{

dout.writeUTF(str);

System.out.println(str);

dout.flush();

}catch(IOException ae){System.out.println(ae);}

}

// client logout

if (e.getSource()==lout){

frame.dispose();

try{

//sending the message for logout

dout.writeUTF(name+" has Logged out");

dlout.writeUTF(name);

dlout.flush();

Thread.currentThread().sleep(1000);

System.exit(1);

}catch(Exception oe){}

}

}

public void windowClosing(WindowEvent w){

33

Page 34: Chat Server Report

CHAT SERVER

try{

dlout.writeUTF(name);

dlout.flush();

Thread.currentThread().sleep(1000);

System.exit(1);

}catch(Exception oe){}

}

}

// class is used to maintaning the list of user name

class My1 implements Runnable{

DataOutputStream dout1;

DefaultListModel model1;

DataInputStream din1;

String name,lname;

ArrayList alname=new ArrayList(); //stores the list of user

names

ObjectInputStream obj; // read the list of user names

int i=0;

My1(DataOutputStream dout1,DefaultListModel model1,String

name,DataInputStream din1){

this.dout1=dout1;

this.model1=model1;

this.name=name;

34

Page 35: Chat Server Report

CHAT SERVER

this.din1=din1;

}

public void run(){

try{

dout1.writeUTF(name); // write the user name in output

stream

while(true){

obj=new ObjectInputStream(din1);

//read the list of user names

alname=(ArrayList)obj.readObject();

if(i>0)

model1.clear();

Iterator i1=alname.iterator();

System.out.println(alname);

while(i1.hasNext()){

lname=(String)i1.next();

i++;

//add the user names in list box

model1.addElement(lname);

}

}

}catch(Exception oe){}

}

}

35

Page 36: Chat Server Report

CHAT SERVER

//class is used to received the messages

class My implements Runnable{

DataInputStream din;

DefaultListModel model;

My(DataInputStream din, DefaultListModel model){

this.din=din;

this.model=model;

}

public void run(){

String str1="";

while(true){

try{

str1=din.readUTF(); // receive the message

// add the message in list box

model.addElement(str1);

}catch(Exception e){}

}

}

}

3. Myserver.java

/

********************************************************

********

36

Page 37: Chat Server Report

CHAT SERVER

*

* Description

* This is a Server Side application of Chat System.

* This application is used for receiving the messages from any

client

* and send to each and every client and in this we can maintain

the

* list of all online users.

*

* Remarks

* This application is unable to provide the private chatting facility

********************************************************

**********/

import java.io.*;

import java.net.*;

import java.util.*;

public class MyServer{

ServerSocket ss;

Socket s;

ArrayList al=new ArrayList();

ArrayList al1=new ArrayList();

ArrayList al2=new ArrayList();

37

Page 38: Chat Server Report

CHAT SERVER

ArrayList alname=new ArrayList();

Socket s1,s2;

MyServer()throws IOException{

ss=new ServerSocket(1004); // create server socket

while(true){

s=ss.accept(); //accept the client socket

s1=ss.accept();

s2=ss.accept();

al.add(s); // add the client socket in arraylist

al1.add(s1);

al2.add(s2);

System.out.println("Client is Connected");

MyThread2 m=new MyThread2(s2,al2,alname);

//new thread for maintaning the list of user name

Thread t2=new Thread(m);

t2.start();

MyThread r=new MyThread(s,al);//new thread for

receive and sending the messages

Thread t=new Thread(r);

t.start();

MyThread1 my=new MyThread1(s1,al1,s,s2); // new

thread for update the list of user name

38

Page 39: Chat Server Report

CHAT SERVER

Thread t1=new Thread(my);

t1.start();

}

}

public static void main(String[] args){

try{

new MyServer();

}catch (IOException e){}

}

}

//class is used to update the list of user name

class MyThread1 implements Runnable{

Socket s1,s,s2;

static ArrayList al1;

DataInputStream ddin;

String sname;

MyThread1(Socket s1,ArrayList al1,Socket s,Socket s2){

this.s1=s1;

this.al1=al1;

this.s=s;

this.s2=s2;

}

public void run(){

try{

39

Page 40: Chat Server Report

CHAT SERVER

ddin=new DataInputStream(s1.getInputStream());

while(true){

sname=ddin.readUTF();

System.out.println("Exit :"+sname);

MyThread2.alname.remove(sname);//remove the logout

user name from arraylist

MyThread2.every();

al1.remove(s1);

MyThread.al.remove(s);

MyThread2.al2.remove(s2);

if(al1.isEmpty())

System.exit(0); //all client has been logout

}

}catch(Exception ie){}

}

}

// class is used to maintain the list of all online users

class MyThread2 implements Runnable{

Socket s2;

static ArrayList al2;

static ArrayList alname;

static DataInputStream din1;

static DataOutputStream dout1;

40

Page 41: Chat Server Report

CHAT SERVER

MyThread2(Socket s2,ArrayList al2,ArrayList alname){

this.s2=s2;

this.al2=al2;

this.alname=alname;

}

public void run(){

try{

din1= new DataInputStream(s2.getInputStream());

alname.add(din1.readUTF()); // store the user name in

arraylist

every();

}catch(Exception oe){System.out.println("Main

expression"+oe);}

}

// send the list of user name to all client

static void every()throws Exception{

Iterator i1=al2.iterator();

Socket st1;

while(i1.hasNext()){

st1=(Socket)i1.next();

dout1=new

DataOutputStream(st1.getOutputStream());

41

Page 42: Chat Server Report

CHAT SERVER

ObjectOutputStream obj=new

ObjectOutputStream(dout1);

obj.writeObject(alname); //write the list of users in

stream of all clients

dout1.flush();

obj.flush();

}

}

}

//class is used to receive the message and send it to all clients

class MyThread implements Runnable{

Socket s;

static ArrayList al;

DataInputStream din;

DataOutputStream dout;

MyThread(Socket s, ArrayList al){

this.s=s;

this.al=al;

}

public void run(){

String str;

int i=1;

try{

42

Page 43: Chat Server Report

CHAT SERVER

din=new DataInputStream(s.getInputStream());

}catch(Exception e){}

while(i==1){

try{

str=din.readUTF(); //read the message

distribute(str);

}catch (IOException e){}

}

}

// send it to all clients

public void distribute(String str)throws IOException{

Iterator i=al.iterator();

Socket st;

while(i.hasNext()){

st=(Socket)i.next();

dout=new DataOutputStream(st.getOutputStream());

dout.writeUTF(str);

dout.flush();

}

}

}

43

Page 44: Chat Server Report

CHAT SERVER

BIBLIOGRAPHY

The following books are being used to fulfill the requirements of the proposed project

and are helpful in the understanding, development and the maintenance of the project:

1. Software Engineering Roger S. Pressman

2. java K.A.Mugal

3. Database System Concepts Henry F. Korth

5. Structured Query Language Ivan Bayros

Websites Visited:

www.java.sun.com

www.google.com

44