Professional Documents
Culture Documents
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
1
SANT GAJANAN MAHARAJ RURAL HOSPITAL &RESEARCH CENTER, MAHAGAON
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.
2
INDEX
1.0 Index
Sr. no. Title Page no.
1. Index 3
Annexure-I Micro-Project 5
Report
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
10 Literature Review 7
3
12. Resources Required 8
17. Conclusion 15
18. Refecence 15
4
Annexure- I Micro project Proposal
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.
5
output.
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.
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
8
-When server receives a message from client:
-When server receives message from another client and send message to him
again:
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);
// Client1 Send
BufferedReader br = new BufferedReader(
new InputStreamReader(s1.getInputStream())
);
// 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())
);
}
}
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;
12
catch(IOException e){
e.printStackTrace();
System.out.println("Socket read Error");
}
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;
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;
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");
}
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.
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