Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Chatting Application Full File PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

Session

2021-202
2

A MINI-PROJECT
REPORT ON
“CHATTING APPLICATION ”

Submitted by

NAMAN TIWARI 1900640100032


MOHD MOIZ QURESHI 1900640100030

Department of Computer Science & Engineering


CERTIFICATE

Certified that the mini-project work entitled “CHATTING APPLICATION” is a bona fide work carried out by

NAMAN TIWARI 1900640100032


MOHD MOIZ QURESHI 1900640100030

There port has been approved as it satisfies the academic requirements in respect of mini-project work prescribed
for the course.

……………….……………..
Mr. PRAVEEN GUPTA
Mini-Project Coordinator

…….……………...………………
Dr. MUNISH KHANNA
Head of the Department
ABSTRACT

Teleconferencing or chatting refers to any kind of communication that


offers a real-time transmission of messages from sender to the receiver.
Chatting is a method of using technology to bring people and ideas
together despite the geographical barriers. The technology to provide the
chatting facility has been available for years, but the acceptance is quite
recent. Analysis of chatting provides an overview of the technologies
used, available features, functions, system of the architecture of the
application, the structure of database of an Instant Messaging
application: I-Chat(IC). The objective of IC application is to facilitate
text messaging, group chatting option, data transfer without size
restriction which is commonly seen in most of the messaging
applications.
ACKNOWLEDGEMENT

The satisfaction that accompanies that the successful completion of any


task would be incomplete without the mention of people whose ceaseless
cooperation made it possible, whose constant guidance and
encouragement crown all efforts with success.

We are indebted to our project guide Mr. Praveen Gupta (Mini-Project


Co-ordinator) for giving us an opportunity to undertake this project and
providing us with his crucial feedback that influenced the development of
this work without which we would not have been able to complete this
project.

We are thankful to Dr. Munish Khanna (Head of the Department, CSE) and all
other faculty member for their kind support in carrying us out this work in the
college successfully.

We also express our gratitude and thanks to our staff tutors and all other
faculty members of the department of Computer Science and Engineering,
Hindustan College of Engineering and Technology, for their quick help and
expert opinions for completing this project.

Naman Tiwari (1900640100032)

Mohd Moiz Qureshi (1900640100030)


TABLE OF CONTENT

ABSTRACT 1

ACKNOWLEDGEMENT 2

1. INTRODUCTION 4

OBJECTIVE 5

REQUIREMENTS 6

2. OPERATIONAL CONCEPTS 7

3. PROJECT SCOPE 8

SERVER 8

CLIENT 13

RESULT AND SNAPSHOT 17

4. FUTURE WORK 18

5. CONCLUSION 19

6. REFERENCES… 20
INTRODUCTION

Chatting Application is a desktop based application.


This client server chat application is based on java swing and used socket package. its
simple and easy and require only core java knowledge. I have taken this program from
internet and modified a little bit to make it simpler and more elegant.
This application/program is a good example of using java.io, java.net package to create a
chat application. A beginner of java language, who is familiar with this packages can able,
be beneficiate.

Chatting is a method of using technology to bring people and ideas “together”


despite of the geographical barriers. The technology has been available for years
but the acceptance it was quit recent. Our project is an example of a multiple client
chat server.
It is made up of 2 applications the client application, which runs on the user’s Pc
and server application, which runs on any Pc on the network. To start chatting
client should get connected to server. We will focus on TCP and UDP socket
connections which are a fundamental part of socket programming.

Keywords: sockets, client-server, Java network programming-socket


functions, Multicasting etc.
MAIN OBJECTIVE

The aim of this project is to express how we can implement a simple chat application between a
server and a client? The application is a desktop based application and is implemented using
Swing and awt. The project is developed in Java SE language executed on a single stand-alone
java across a network using loop back address concept.

Application consists of two programs:

Server

Client

Server

The server module of the application waits for the client to connect to it. Then if connection is
granted a client interacts communicates and connects to the server, it can mutually
communicate with the server. The duty of the server is to let clients exchange the messages.

Client
The client module is the one that utilizer sends requests to the server. Utilizer utilizes the
client as the means to connect to the server. Once he establishes the connection, he can
communicate to the connected server.
REQUIREMENTS

External Interface Requirements


User Interface

The user interface required to be developed for the system should be user
friendly and attractive.
There are two sets of Java APIs for graphics programming:

AWT(Abstract Windowing Toolkit) and Swing.

⮚ AWT API was introduced in JDK 1.0. Most of the AWT


components have become obsolete and should be replaced by
newer Swing components.

⮚ Swing API, a much more comprehensive set of graphics libraries


that enhances the AWT, was introduced as part of Java Foundation
Classes (JFC) after the release of JDK 1.1. JFC consists of Swing,
Java2D, Accessibility, Internationalization, and Pluggable
Look-and-Feel Support APIs. JFC was an add-on to JDK 1.1 but
has been integrated into core Java since JDK 1.2.

Software Interfaces
Programming Language: JAVA
&
SOCKET PROGRAMMING

Operational Concepts and Scenarios

Operation of the application based on the inputs given by the user:

When the run button is clicked then the chat form is initialized with a
connection

● between the host and the client machine.

Note: server must be started at first before a client start.

● Contains a rich textbox which send messages from one user to another

● Contains a textbox for messages to be written that is sent across the network.

● Contains a Send button

.∙ When the sent button is clicked, in the background, the text in the textbox is
encoded

● and sent as a packet over the network to the client machine. Here this
message is decoded and is shown in the rich textbox.
Project Scope
This project can be mainly divided into two modules:

1. Server

2. Client

This project is mainly depended on client/server model. The client requests the
server and server responses by granting the clients request. The proposed system
should provide both of the above features along with the followed ones:

Server
A server is a computer program that provides services to other computer
programs (and their users) in the same or other computers. The computer that a
server program runs in is also frequently referred to as a server. That machine
may be a dedicated server or used for other purposes as well. Example Server,
Database, Dedicated, Fileserver, Proxy Server, Web Server. The server is
always waiting for client’s requests. The client come and goes down but the
server remains the same.

A server application normally listens to a specific port waiting for connection


requests from a client. When a connection request arrives, the client and the
server establish a dedicated connection over which they can communicate.
During the connection process, the client is assigned a local port number, and
binds a socket to it. The client talks to the server by writing to the socket and gets
information from the server by reading from it. Similarly, the server gets a new
local port number (it needs a new port number so that it can continue to listen for
connection requests on the original port). The server also binds a socket to its
local port and communicates with the client by reading from and writing to it. The
client and the server must agree on a protocol that is, they must agree on the
language of the information transferred back and forth
through the socket. Normally, a server runs on a specific computer and has a socket
that is bound to a specific port number. The server just waits, listening to the socket
for a client to make a connection request.

Server Program
});

ImageIcon i4 = new
ImageIcon(ClassLoader.getSystemResource("com/company/icons/server1.png"));
Image i5 = i4.getImage().getScaledInstance(60, 60, Image.SCALE_DEFAULT);
ImageIcon i6 = new ImageIcon(i5);
JLabel l2 = new JLabel(i6);
l2.setBounds(40, 5, 60, 60);
p1.add(l2);

ImageIcon i7 = new
ImageIcon(ClassLoader.getSystemResource("com/company/icons/video.png"));
Image i8 = i7.getImage().getScaledInstance(30, 30, Image.SCALE_DEFAULT);
ImageIcon i9 = new ImageIcon(i8);
JLabel l5 = new JLabel(i9);
l5.setBounds(290, 20, 30, 30);
p1.add(l5);

ImageIcon i11 = new


ImageIcon(ClassLoader.getSystemResource("com/company/icons/phone.png"));
Image i12 = i11.getImage().getScaledInstance(35, 30, Image.SCALE_DEFAULT);
ImageIcon i13 = new ImageIcon(i12);
JLabel l6 = new JLabel(i13);
l6.setBounds(350, 20, 35, 30);
p1.add(l6);

ImageIcon i14 = new


ImageIcon(ClassLoader.getSystemResource("com/company/icons/3icon.png"));
Image i15 = i14.getImage().getScaledInstance(13, 25, Image.SCALE_DEFAULT);
ImageIcon i16 = new ImageIcon(i15);
JLabel l7 = new JLabel(i16);
l7.setBounds(410, 20, 13, 25);
p1.add(l7);

JLabel l3 = new JLabel("Server");


l3.setFont(new Font("SAN_SERIF", Font.BOLD, 18));
l3.setForeground(Color.WHITE);
l3.setBounds(110, 15, 100, 18);
p1.add(l3);

JLabel l4 = new JLabel("Active Now"); l4.setFont(new


Font("SAN_SERIF", Font.PLAIN, 14));
l4.setForeground(Color.WHITE);
l4.setBounds(110, 35, 100, 20);
p1.add(l4);

Timer t = new Timer(1, new ActionListener(){


public void actionPerformed(ActionEvent ae){
if(!typing){
l4.setText("Active Now");
}
}
});

t.setInitialDelay(2000);

a1 = new JPanel();
a1.setBounds(5, 75, 440, 570);
a1.setFont(new Font("SAN_SERIF", Font.PLAIN, 16));
f1.add(a1);
t1 = new JTextField();
t1.setBounds(5, 655, 310, 40);
t1.setFont(new Font("SAN_SERIF", Font.PLAIN, 16));
f1.add(t1);

t1.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent ke){
l4.setText("typing...");

t.stop();

typing = true;
}

public void keyReleased(KeyEvent ke){


typing = false;

if(!t.isRunning()){
t.start();
}
}
});

b1 = new JButton("Send");
b1.setBounds(320, 655, 123, 40);
b1.setBackground(new Color(7, 94, 84));
b1.setForeground(Color.WHITE);
b1.setFont(new Font("SAN_SERIF", Font.PLAIN, 16));
b1.addActionListener(this);
f1.add(b1);

f1.getContentPane().setBackground(Color.WHITE);
f1.setLayout(null);
f1.setSize(450, 700);
f1.setLocation(250, 20);
f1.setUndecorated(true);
f1.setVisible(true);

public void actionPerformed(ActionEvent ae){


try{
String out = t1.getText();

JPanel p2 = formatLabel(out);

a1.setLayout(new BorderLayout());

JPanel right = new JPanel(new BorderLayout());


right.add(p2, BorderLayout.LINE_END);
vertical.add(right);
vertical.add(Box.createVerticalStrut(15));

a1.add(vertical, BorderLayout.PAGE_START);

//a1.add(p2);
dout.writeUTF(out);
t1.setText("");
}catch(Exception e){
System.out.println(e);
}
}

public static JPanel formatLabel(String out){


JPanel p3 = new JPanel();
p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
JLabel l1 = new JLabel("<html><p style = \"width :
150px\">"+out+"</p></html>");
THE SERVER SCREEN
Client

On the client site the client knows the hostname of the machine on which the
server is running and the port number on which the server is listening.

To make a connection request, the client tries to rendezvous with the server on the
server's machine and port. The client also needs to identify itself to the server so it
binds to a local port number that it will use during this connection. This is usually
assigned by the system.

The model used for this project is the single server –

Single client models.

The following specifications must be implemented:

1. The server and client are two separate programs.

Client Program
package com.company;

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*; import
java.awt.event.*; import
java.net.*; import
java.io.*;

import java.util.Calendar;
import java.text.SimpleDateFormat;
import javax.swing.*;

public class client implements ActionListener {

JPanel p1;
JTextField t1;
JButton b1; static
JPanel a1;
static JFrame f1 = new JFrame();

static Box vertical = Box.createVerticalBox();

static Socket s;
static DataInputStream din;
static DataOutputStream dout;

Boolean typing;

client() {
f1.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

p1 = new JPanel();
p1.setLayout(null);
p1.setBackground(new Color(7, 94, 84));
p1.setBounds(0, 0, 450, 70);
f1.add(p1);

ImageIcon i1 = new
ImageIcon(ClassLoader.getSystemResource("com/company/icons/3.png"));
Image i2 = i1.getImage().getScaledInstance(30, 30, Image.SCALE_DEFAULT);
ImageIcon i3 = new ImageIcon(i2);
JLabel l1 = new JLabel(i3);
l1.setBounds(5, 17, 30, 30);
p1.add(l1);

l1.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent ae) {
System.exit(0);
}
});

ImageIcon i4 = new
ImageIcon(ClassLoader.getSystemResource("com/company/icons/2.png"));
Image i5 = i4.getImage().getScaledInstance(60, 60, Image.SCALE_DEFAULT);
ImageIcon i6 = new ImageIcon(i5);
JLabel l2 = new JLabel(i6);
l2.setBounds(40, 5, 60, 60);
p1.add(l2);

ImageIcon i7 = new
ImageIcon(ClassLoader.getSystemResource("com/company/icons/video.png"));
Image i8 = i7.getImage().getScaledInstance(30, 30, Image.SCALE_DEFAULT);
ImageIcon i9 = new ImageIcon(i8);
JLabel l5 = new JLabel(i9);
l5.setBounds(290, 20, 30, 30);
p1.add(l5);

ImageIcon i11 = new


ImageIcon(ClassLoader.getSystemResource("com/company/icons/phone.png"));
Image i12 = i11.getImage().getScaledInstance(35, 30, Image.SCALE_DEFAULT);
ImageIcon i13 = new ImageIcon(i12);
JLabel l6 = new JLabel(i13);
l6.setBounds(350, 20, 35, 30);
p1.add(l6);

ImageIcon i14 = new


ImageIcon(ClassLoader.getSystemResource("com/company/icons/3icon.png"));
Image i15 = i14.getImage().getScaledInstance(13, 25, Image.SCALE_DEFAULT);
ImageIcon i16 = new ImageIcon(i15);
JLabel l7 = new JLabel(i16);
l7.setBounds(410, 20, 13, 25);
p1.add(l7);

JLabel l3 = new JLabel("Client");


l3.setFont(new Font("SAN_SERIF", Font.BOLD, 18));
l3.setForeground(Color.WHITE);
l3.setBounds(110, 15, 100, 18);
p1.add(l3);

JLabel l4 = new JLabel("Active Now"); l4.setFont(new


Font("SAN_SERIF", Font.PLAIN, 14));
l4.setForeground(Color.WHITE);
l4.setBounds(110, 35, 100, 20);
p1.add(l4);

Timer t = new Timer(1, new ActionListener() {


public void actionPerformed(ActionEvent ae) {
if (!typing) {
l4.setText("Active Now");
}
}
});

t.setInitialDelay(2000);

a1 = new JPanel();
a1.setBounds(5, 75, 440, 570);
a1.setFont(new Font("SAN_SERIF", Font.PLAIN, 16));
f1.add(a1);

t1 = new JTextField();
t1.setBounds(5, 655, 310, 40);
t1.setFont(new Font("SAN_SERIF", Font.PLAIN, 16));
f1.add(t1);

t1.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent ke) {
l4.setText("typing...");

t.stop();

typing = true;
}

public void keyReleased(KeyEvent ke) {


typing = false;
if (!t.isRunning()) {
t.start();
}
}
});

b1 = new JButton("Send");
b1.setBounds(320, 655, 123, 40);
b1.setBackground(new Color(7, 94, 84));
b1.setForeground(Color.WHITE);
b1.setFont(new Font("SAN_SERIF", Font.PLAIN, 16));
b1.addActionListener(this);
f1.add(b1);

f1.getContentPane().setBackground(Color.WHITE);
f1.setLayout(null);
f1.setSize(450, 700);
f1.setLocation(900, 20);
f1.setUndecorated(true);
f1.setVisible(true);

public void actionPerformed(ActionEvent ae) {

try {
String out = t1.getText();

JPanel p2 = formatLabel(out);

a1.setLayout(new BorderLayout());

JPanel right = new JPanel(new BorderLayout());


right.add(p2, BorderLayout.LINE_END);
vertical.add(right);
vertical.add(Box.createVerticalStrut(15));

a1.add(vertical, BorderLayout.PAGE_START);

//a1.add(p2);
dout.writeUTF(out);
t1.setText("");
} catch (Exception e) {
System.out.println(e);
}
}

public static JPanel formatLabel(String out) {


JPanel p3 = new JPanel();
p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));

JLabel l1 = new JLabel("<html><p style = \"width : 150px\">" + out +


"</p></html>");
l1.setFont(new Font("Tahoma", Font.PLAIN, 16));
l1.setBackground(new Color(37, 211, 102));
l1.setOpaque(true);
l1.setBorder(new EmptyBorder(15, 15, 15, 50));

Calendar cal = Calendar.getInstance(); SimpleDateFormat


sdf = new SimpleDateFormat("HH:mm");

JLabel l2 = new JLabel();


l2.setText(sdf.format(cal.getTime()));

p3.add(l1);
p3.add(l2);
return p3;
}
THE CLIENT SCREEN
THE CLIENT SERVER SCREEN
Future work
There is always a room for improvements in any software package, however
good and efficient it may be done. But the most important thing should be
flexible to accept further modification. Right now we are just dealing with text
communication. In future this software may be extended to include features such
as:
Files transfer: this will enable the user to send files of different formats to others
via the chat∙ application.
Voice chat: this will enhance the application to a higher level where
communication will be possible via voice calling as in telephone.

Video chat: This will further enhance the feature of calling into video
communication.
Conclusion

I developed network applications in Java by using sockets, threads, and


Web services.
This software is portable, efficient, and easily maintainable for large
number of clients. Our developed web-based chatting software is unique in
its features and more importantly easily customizable. The java.net package
provides a powerful and flexible set of classes for implementing network
applications. Typically, programs running on client machines make requests
to programs on a server Machine. These involve networking services
provided by the transport layer. The most widely used transport protocols
on the Internet are TCP (Transmission control Protocol) and UDP (User
Datagram Protocol).
TCP is a connection-oriented protocol providing a reliable flow of data
between two computers. On the other hand, UDP is a simpler message-
based connectionless protocol which sends packets of data known as
datagram’s from one computer to another with no guarantees of arrival.
REFERENCES

Websites:

● https://www.w3schools.com/
● https://www.codewithharry.com/
● https://hcst.edu.in/
● https://erp.aktu.ac.in/

YouTube Channels:

● Apna College
● Code for Interview
● Gate Smashers
● Code with Harry
● PepCoding

You might also like