Multi-Threaded Server Client Chat Model
-
Upload
karan-khare -
Category
Documents
-
view
559 -
download
5
Transcript of Multi-Threaded Server Client Chat Model
MULTI-THREADED SERVER CLIENT
CHAT MODEL
By: Karan Khare
A2305208514
Cs4-y
AIM OF THE PROJECT
To attain a chat model which can perform many
processes or tasks at same time with very low
halting problem i.e. a Multi-Threaded Server Client
Chat Model.
INTRODUCTION
A networking is a set of devices (often referred to as nodes) connected
by communication links. A node can be a computer, printer, or any other
device capable of sending and/or receiving data generated by other
nodes.
Socket programming is the basis for developing networking applications
it can be done in c, c++, Java etc.
A simple Server Client Chat application is the basics of networking
application.
Here is the Multi-threaded Sever Client Chat Model (An enhanced
version of Simple Server Client Chat Model).
INTRODUCTION CONT…
The Language used for developing the Application is Java.
The Application performs task of sending a message from
one client to another and at the same time receiving the
message from another client with almost no delay of time.
Feature achieved through a very powerful feature of Java
called Multi-Threading.
REQUIREMENTS
Hardware Requirements• Processor: Intel Pentium 2 or higher• Speed: 1GHz +• RAM: 256 MB or Higher• Free Disk Space: Minimum 100 MB of free Disk Space
Network Requirements• The System should Have a Ethernet card or LAN card.• The System Should LAN network (Local Area Network).
Software Requirements• JDK1.2 (Java Development Kit version 1.2) or higher (depending upon the
operating System used)
JRE (Java Runtime Environment)
Operating System: Windows 98 or higher, Linux, Open Solaris, Apple MAC
OS
LANGUAGE ENVIRONMENT
Developed in Java since Java provides already pre-
existing API’s or Application Programming Interface
for networking(Socket Programming), GUI
development, Even Handling, Threading etc.
Thus Java making application development a easy
piece of cake to work upon and develop.
WORKING OF THE APPLICATION
There is a simple Server which accepts request from clients
and provides them connection and handles there chat session.
The Stream Communication Protocol is TCP/IP protocol( a
connection oriented protocol).
CONTINUE…..1
Class Socket implements the client side and the class ServerSocket
class implements the server side of the two-way link. .
The client request the server at some IP address and TCP port
number.
To communicate over a socket connection, I/O streams in Java are
used(performs read/write operations).
CONTINUE…..2
InputStreamReader chained to the socket’s low-level(Connection) Input
Stream withInputStreamreader stream=new InputStreamReader(chatsocket.getInputStream());
InputStreamReader is the ‘bridge’ between a low level byte stream (like the
one coming from the socket) and a high level character stream
BufferedReader
Now Finally chain the BufferedReader to the already chained
InputStreamReaderBufferefReader reader=new BufferedReader(stream);String message=reader.readLine();
CONTINUE…..3
Now to write data to a socket PrintWriter class is used which
has print() and println() method.
With the similar procedure as in reading data PrintWriter is
also chained to the Socket’s low-level (Connection) output-
stream. PrintWriter writer=new PrintWriter(chatSocket.getOutputStream());
Now to write a message we use writer.println(“message to send!”) ;
CONTINUE…..4
Threads in Java are used to make application perform
multiple processes at same time, it doesn’t actually happens
like but appears.
To create a thread we write the statement asThread t=new thread();t.start();
Multi-threading in java means looking at both the thread and
the job that’s run by the thread.
CONTINUE…..5
DEVELOPED APPLICATION
Client A
Server
Client B Client C
DATAFLOW DIAGRAMCreate a stream socket sock
Create a intermediate stream reader for conversion of byte to char
Accept the connection if any for client
Create the client socket sock
Create a stream ServerSocket serversock
Read and write the message simultaneously
Create high Level BufferedReader
Request Server for connection
Create a Thread
Initiate the thread to send and forward message
Client Server
Client Request Approved
CONCLUSION
Finally a Chat system is obtained which can handle
simultaneous tasks like receiving and sending
message at same time with high efficiency and very
low halting problem if many clients are connected
together.
THANKYOU