You are on page 1of 16

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION,

MUMBAI

A Project Report
On
‘Implement Chat Server using ServerSocket
And Multiple Socket Class’

DIPLOMA
In
Computer ENGINEERING
Submitted by
Mr. Shankar Maruti Morti
Mr. Bhushan Siddhappa Karguppi
Mr. Shreyash Tanaji Magdum
Mr. Prathmesh Yashwant Sardesai

Under guidance of,


Mr. A. T. Narvekar

DEPARTMENT OF COMPUTER ENGINEERING

SANT GAJANAN MAHARAJ RURAL POLITECHNIC,


MAHAGAON
ACADEMIC YEAR 2023-2024

1
SANT GAJANAN MAHARAJ RURAL HOSPITAL &RESEARCH CENTER, MAHAGAON

“SANT GAJANAN MAHARAJ RURAL


POLYTECHNIC”
A/P –MAHAGAON, SITE –CHINCHEWADI, TAL-GADHINGLAJ, DIST-KOLHAPUR

Certificate
This is to certify that the following students of Fifth semester of Diploma in
Computer Engineering of Institute SANT GAJANAN RURAL POLYTECHNIC,
MAHAGAON-416503.(CODE-0965) has completed Micro project on ‘Implement Chat
Server using ServerSocket And Multiple Socket Class’ in subject AJP subject-code(22517)
for academic year 2023 to 2024 as prescribed in the curriculum.

ROLL ENROLLMENT NO NAME OF STUDENT


SEAT NO
NO
22 2109650147 Bhushan Siddhappa Karguppi
33 2109650173 Shankar Maruti Morti
35 2109650175 Shreyash Tanaji Magdum
28 2109650163 Prathmesh Yashwant Sardesai

DATE: PLACE: Mahagaon

Mr. A. T. Narvekar Mr. G. K. Birangaddi Mrs. R. S. Patil


(Project Guide) (Head of Department) (Principal)

2
INDEX

1.0 Index
Sr. no. Title Page no.

1. Index 3

Annexure-I Micro-Project 5
Report

2. Aims of the micro-project 5

3. Intended Course Outcomes 5

4. Proposed Methodology 5

5. Action Plan 5

6. Resources Required 6

Annexure-II Micro-Project 7
Report

7. Rationale 7

8. Aim of micro-project 7

9. Intended Course Outcome 7

10 Literature Review 7

11. Actual Methodology Followed 7

3
12. Resources Required 8

13. Output of the Micro-Project 8

14. Skills developed out of the micro- 24


project

15. Application of this Micro-Project 15

16. Future scope 15

17. Conclusion 15

18. Refecence 15

4
Annexure- I Micro project Proposal

“One to Many Server-Client Chat System”

1.0 Rationale:
Here is a project named “One to many Server-Client chat system”. In this project
there is one proper Server and three clients, these three clients can chat or
communicate to that one Server respectively. This project is done in language ‘java’
with some other libraries like java.io and java.net. These are two major packages
used in it. The ‘ServerSocket’ and ‘Socket’ these are two most important classes
used in this program. The project can run on any operating system having JDK.
Four individual terminals are required to use this program.

2.0 Aim of the Micro-Project


To develop a communication program between the three Clients and one Server.

3.0 Intended Course Outcomes


a) CO301.15: Develop java programs using networking concepts.

4.0 Proposed Methodology


 First had a search on what topic to be chosen by teacher guide and then we selected the
information.
 Searched on the allotted project and then developed a report accordingly
 Gained knowledge from the search of the project
 This helped us to know more about the project in detail and we gained knowledge of it.
 We develop a report for the searched project.
 We checked the report from the teacher guardians

5.0 Action plan


Sr. no. Action Details Start Date End Date Name of Team
Member
Selected the topic. Bhushan Karguppi
1.
Searched for Shankar Morti
2. information about the
project topic.
Create logic to Shreyash Magdum
3. develop the required

5
output.

Made the report. Prathmesh Sardesai


4.
Consulted with Bhushan Karguppi
5. teacher to check the
report.
Modified the report. Prathmesh Sardesai
6.
Made output of the Shreyash Magdum
7. project
Showed output to Shankar Morti
8. teacher.
Submitted the final Bhushan Karguppi
9. project.

6.0 Resource Required:

Sr. Name of resource /


Specification Quantity Remarks
No. material
Intel(R) Core (TM)
1. Computer system i31450 CPU32 bit 1 Used
operating system

2. Operating System Windows _ Used

3. Runtime Environment for JDK 18.0. _ Used


java, JDK

4. Visual Studio Code Version 1.60.2 _ Used


(IDE for programming)
Microsoft Office - Excel
4. Software 2013, _ Used
Word 2013

6
Annexure-II Micro-Project Report
“One to many Server-Client chat system”

1.0 Rationale
This project is about a communication system of clients and its server. This program
allows making a clear communication between three clients and one server. First
Server starts, then other three clients start one by one. The Server is programmed by
using the ServerSocket class and the Client is programmed by using Socket class.
These two classes belong from java.net package. This java.net package allows us to
use classes, interfaces, constructors and methods which may be useful while making
networking programs.
In this program first server starts and then clients starts. The communication always
starts from client side. When a communication is completed the next client is allowed
to enter in communication. The communication ends only by clients. By entering
String ‘quit’ the connection closes.

2.0 Aim of the Micro-Project


To develop a communication program between the three Clients and one Server.

3.0 Intended Course Outcomes


a) CO301.15: Develop java programs using networking concepts.

4.0 Literature Review


In the follow project the java networking concept is used. Java Networking is a
concept of connecting two or more computing devices together so that we can share
resources. Java socket programming provides facility to share data between different
computing devices. The application layer of java program communicates with the
network. The java.net package contains all of the java networking classes and
interfaces.

5.0 Actual Methodology followed


 First had a search on what topic to be chosen and then we selected the information.
 Searched on the allotted project and then developed a report accordingly.
 Gained knowledge from the search of the project.
 This helped me to know more about the project in detail and we gained knowledge of
it.
 We developed the program.
 We checked the program under the teacher guardians.

7
6.0 Resources Used
Sr. Name of resource /
Specification Quantity Remarks
No. material
Intel(R) Core (TM)
1. Computer system i31450 CPU32 bit 1 Used
operating system

2. Operating System Windows _ Used

3. Runtime Environment for JDK 18.0. _ Used


java, JDK

4. Visual Studio Code Version 1.60.2 _ Used


(IDE for programming)
Microsoft Office -
4. Software/Application Word 2013, Command _ Used
prompt

7.0 Output of project


 Server side:
The server side has different code from other clients. This server connects to other
clients with the help of threads. A thread called ‘ServerThread’ is created which is
executed every time a new client is connected to server through accept() method.
Output:
-When server starts.

-When connection establishes.

8
-When server receives a message from client:

-When server sends a message to a client:

-When server receives message from another client and send message to him
again:

-When server is closed by client:

9
Server Side:
The client side is made of Socket class from java.net package. There are total five
clients, which mean five different clients use one server with same port. When
new client program starts, a new thread is created in server’s program, hence by
one port number, many clients can work.
Code:
import java.net.ServerSocket;
import java.net.Socket;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.InputStreamReader;
public class ServerSide
{
public static void main(String[] args) throws IOException

{
ServerSocket s = new ServerSocket(2019);
ServerSocket s5 = new ServerSocket(2020);
ServerSocket s2 = new ServerSocket(2021);

System.out.println("Server Started, waiting for client");


Socket s1 = s.accept();
Socket c4 = s5.accept();
Socket c3 = s2.accept();

// Client1 Send
BufferedReader br = new BufferedReader(
new InputStreamReader(s1.getInputStream())
);

OutputStream out = s1.getOutputStream();


PrintStream ps = new PrintStream(out);
BufferedReader br1 = new BufferedReader(
new InputStreamReader(System.in)
);

// Client2 Send
BufferedReader br2 = new BufferedReader(
new InputStreamReader(c4.getInputStream())
);

10
OutputStream out1 = c4.getOutputStream();
PrintStream ps1 = new PrintStream(out);
BufferedReader br3 = new BufferedReader(
new InputStreamReader(System.in)
);
// Client3 Send
BufferedReader br4 = new BufferedReader(
new InputStreamReader(c3.getInputStream())
);

OutputStream out2 = c3.getOutputStream();


PrintStream ps2 = new PrintStream(out);
BufferedReader br5 = new BufferedReader(
new InputStreamReader(System.in)
);
do{
String res = br.readLine();

System.out.println("Client Send: "+res);


System.out.print("Server: ");
String msg = br1.readLine();
System.out.print("\n\n");
ps.println(msg);
// client 2
String res1 = br2.readLine();
System.out.println("Client Send: "+res1);
System.out.print("Server: ");
String msg1 = br3.readLine();
System.out.print("\n\n");
ps.println(msg1);
// client 3
String res2 = br4.readLine();
System.out.println("Client Send: "+res2);
System.out.print("Server: ");
String msg2 = br5.readLine();
System.out.print("\n\n");
ps.println(msg2);
}
while(true);

}
}

11
Client one-1:
-When message is sent to server and received also:

Code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class NetworkClient1 {


public static void main(String args[]) throws IOException{
System.out.println("\t\t<- Client One-1 ->");
// declaring important objects and variables
InetAddress address=InetAddress.getLocalHost();
Socket s1=null;
String line="Client first: ";
BufferedReader br=null;
BufferedReader is=null;
PrintWriter os=null;

s1=new Socket(address, 4445);


br= new BufferedReader(new InputStreamReader(System.in));
is=new BufferedReader(new InputStreamReader(s1.getInputStream()));
os= new PrintWriter(s1.getOutputStream());

//starting program from here


System.out.println("Enter Data to echo Server ( Enter QUIT to end):");
String response=null;
try {
line=line.concat(br.readLine());
//take input by client
while(line.indexOf("QUIT")==-1){
//while() loop executes until client enter 'close'
os.println(line);
//print input to server side
os.flush();
response=is.readLine();
//take input by server
System.out.println("Server's Response : "+response+"\n");
line="Client two: ";
String a="";
System.out.print("Enter message :"+a);
a=br.readLine();
//take input by client again
line=line.concat(a) ;
}
}

12
catch(IOException e){
e.printStackTrace();
System.out.println("Socket read Error");
}

//closing all streams, connections and sockets


finally{
is.close();os.close();br.close();s1.close();
System.out.println("Connection Closed");
}
}}

1. Client two-2:
-When message is sent to server and received also:

Code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class NetworkClient2 {


public static void main(String args[]) throws IOException{
System.out.println("\t\t<- Client Two-2 ->");
//declaring and defining objects and variables
InetAddress address=InetAddress.getLocalHost();
Socket s1=null;
String line="Client two: ";
BufferedReader br=null;
BufferedReader is=null;
PrintWriter os=null;

s1=new Socket(address, 4445);


br= new BufferedReader(new InputStreamReader(System.in));
is=new BufferedReader(new InputStreamReader(s1.getInputStream()));
os= new PrintWriter(s1.getOutputStream());

//actual code or logic


System.out.println("Enter Data to echo Server ( Enter QUIT to end):");
String response=null;
try {
line=line.concat(br.readLine()) ;
//take input by client
while(line.indexOf("QUIT")==-1){
//while() loop executes until client enter 'close'
os.println(line);
//print input to server side

13
os.flush();
response=is.readLine();
//take input by server
System.out.println("Server's Response : "+response+"\n");
line="Client two: ";
String a="";
System.out.print("Enter message :"+a);
a=br.readLine(); //take input by client again
line=line.concat(a) ;
}
}
catch(IOException e){
e.printStackTrace();
System.out.println("Socket read Error");
}
//closing all streams, connections and sockets
finally{
is.close();os.close();br.close();s1.close();
System.out.println("Connection Closed");
}
}}

2. Client three-3:
-When message is sent to server and received also:

Code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class NetworkClient3 {


public static void main(String args[]) throws IOException{
System.out.println("\t\t<- Client Three-3 ->");
//declaring and defining objects and variables
InetAddress address=InetAddress.getLocalHost();
Socket s1=null;
String line="Client three: ";
BufferedReader br=null;
BufferedReader is=null;
PrintWriter os=null;

s1=new Socket(address, 4445);


br= new BufferedReader(new InputStreamReader(System.in));
is=new BufferedReader(new InputStreamReader(s1.getInputStream()));
os= new PrintWriter(s1.getOutputStream());

14
//starting program from here
System.out.println("Enter Data to echo Server ( Enter 'QUIT' to end):");
String response=null;
try{
line=line.concat(br.readLine());
//take input by client
while(line.matches("QUIT")==false){
//while() loop executes until client enter 'close'
os.println(line);
//print input to server side
os.flush();
response=is.readLine();
//take input by server
System.out.println("Server's Response : "+response+"\n");
line="Client two: ";
String a="";
System.out.print("Enter message :"+a);
a=br.readLine();
//take input by client again
line=line.concat(a) ;
}
}
catch(IOException e){
e.printStackTrace();
System.out.println("Socket read Error");
}

//closing all streams, connections and sockets


finally{
is.close();os.close();br.close();s1.close();
System.out.println("Connection Closed");
}//catch() to handle if any exception is found by chance
}}

-When client closes the connection:

8.0 Skills developed out of the micro-project


 We get the knowledge of How to use java.net classes and java.io classes from
java.
 We get the knowledge of networking in java, and its practical knowledge.
 We also learn about how to use class exception handling and threads built in java
and etc. while creating logic of the project.

15
9.0 Application of this Micro-Project
Application of this project is that unlike one to one chat system multiple clients can
now chat with server with much more speed and efficiency.

10.0 Future Scope


This one to many communication chat system made in java with visual studio IDE
software would demonstrate how the structure of a basic communication system. With
the help of ‘threads’ and java libraries it is very easy to build an easy, fast and
efficient communication system that a server and clients can use. In future, it can be
more reliable, compatible, easy to use, muti-functional, simple and interactive CLI
(Command Line Interface) and much more functionalities will be added in this
project. This is achieved through the use of java.net library, java.io library, java
threads, java exception handling and much more java concepts.

11.0 Conclusion
Doing communication with one server and many clients with more easiness and
simple looking CLI has been simplified. Previously the chatting system using Server
and ServerSocket class was very limited, like only one client was able to
communicate with the server with only one port, but now with this program one can
use this for one-to-many communication system. This Application provides us with
ease of access, user friendliness and simplified CLI. Also this program has much cool
looking command line interface then normal chat system.

12.0 References:
1. www.stackoverflow.com
2. www.github.com
3. www.tutorials.com
4. www.geeksforgeeks.com

16

You might also like