SlideShare une entreprise Scribd logo
1  sur  20
Multi User Chat System Using
Java
• Multi User Chat System is an application through which
the user can communicate with other users connected in
the same network area (LAN). This works under any
operating system and is programmed in java.
• To establish a communication between the systems, we
need simple socket connections in order to connect them
in a network.
• Socket programming uses the client socket and server
socket methods to connect the local host to the named
host and port
• The communication between various users is done using
server client model.
• Several client machines are connected to their dedicated
server ports and communication is established.
• We use the lowest level of networking techniques
available in java, though there are many ways of
connecting client with the server.
• Hence, we need simple classes of networking package in
order to establish a server client prototype.
What is a server??
• A server is a system (software and suitable computer hardware)
that responds to requests across a computer network to
provide, or help to provide, a network service.
• Servers can be run on a dedicated computer, but many
networked computers are capable of hosting servers. In many
cases, a computer can provide several services and have several
servers running.
• Servers are computer programs running to serve the requests of
other programs, the clients. Thus, the server performs some
task on behalf of clients. The clients typically connect to the
server through the network but may run on the same computer.
In the context of Internet Protocol (IP) networking, a server is a
program that operates as a socket listener.
Client:
Client is a user system which uses its server to get its
program or action executed.
• To have a basic server client connection
through java programming language, we
need the concepts of java as such as,
• 1. Network packages
• 2. Thread classes
• 3. AWT tool kit
• 4. Event handling.
Step by step modules…
* Listener class
* While-Accept loop
* Per-Thread class
* While-Read/Write loop (Server side)
* Removing dead connections
* Client class
* While-Read/Write loop (Client side)
1.What does the server do?
- Stand alone program (JVM)
2.Listening to a port
After a server is ready, get ready to receive
incoming connections.
3. Sockets
- Communications pass through sockets. Socket
has an InputStream and an OutputStream.
• PORT
// Constructor and while-accept loop all in one.
public Server( int port ) throws IOException {
// All we have to do is listen
listen( port );
}
SERVER
// start listening on the port
ServerSocket ss = new ServerSocket( port );
// loop forever
while (true) {
// get a connection
Socket newSocket = ss.accept();
// deal with the connection
The main() routine
// Main routine
// Usage: java Server >port<
static public void main( String args[] ) throws Exception {
// Get the port # from the command line
int port = Integer.parseInt( args[0] );
// Create a Server object, which will automatically begin
// accepting connections.
new Server( port );
4.Serialization of incoming requests
- multithreading.
private void listen( int port ) throws IOException {
// Create the ServerSocket
ss = new ServerSocket( port );
// Tell the world we're ready to go
System.out.println( "Listening on "+ss );
// Keep accepting connections forever
while (true) {
// Grab the next incoming connection
Socket s = ss.accept();
// Tell the world we've got it
System.out.println( "Connection from "+s );
// Create a DataOutputStream for writing data to the
// other side
DataOutputStream dout = new DataOutputStream( s.getOutputStream() );
// Save this stream so we don't need to make it again
outputStreams.put( s, dout );
// Create a new thread for this connection, and then forget
// about it
new ServerThread( this, s );
}
}
5. The communications protocol
* When a user types something into their chat
window, their message will be sent as a
string through a DataOutputStream.
* When the server receives a message, through
a DataInputStream, it will send this same
message to all users, again as a string through a
DataOutputStream.
* The users will use a DataInputStream to
receive the message.
6. Removing dead connections
// The connection is closed for one reason or
another,
// so have the server dealing with it
server.removeConnection( socket );
Now, to the client side
1. Use an interface.
2. Connect to the server
// Connect to the server
try {
// Initiate the connection
socket = new Socket( host, port );
// We got a connection! Tell the world
System.out.println( "connected to "+socket );
// Let's grab the streams and create DataInput/Output streams
// from them
din = new DataInputStream( socket.getInputStream() );
dout = new DataOutputStream( socket.getOutputStream() );
// Start a background thread for receiving messages
new Thread( this ).start();
} catch( IOException ie ) { System.out.println( ie ); }
}
The While-Read/Write loop (Client side)
// Background thread runs this: show messages from
other window
public void run() {
try {
// Receive messages one-by-one, forever
while (true) {
// Get the next message
String message = din.readUTF();
// Print it to our text window
ta.append( message+"n" );
}
} catch( IOException ie ) { System.out.println( ie ); }
}
Pretty simple. Each incoming message gets
displayed in the text display window, and
then the loop goes back to waiting for the
next message.
Limitations:
Cant add a new client when a
communication is under process.
Queries please

Contenu connexe

Tendances

Social messenger introduction
Social messenger introductionSocial messenger introduction
Social messenger introductiondeepakrajput022
 
Chat Room System using Java Swing
Chat Room System using Java SwingChat Room System using Java Swing
Chat Room System using Java SwingTejas Garodia
 
How to build a chat application with react js, nodejs, and socket.io
How to build a chat application with react js, nodejs, and socket.ioHow to build a chat application with react js, nodejs, and socket.io
How to build a chat application with react js, nodejs, and socket.ioKaty Slemon
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycleDhruvin Nakrani
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming TutorialJignesh Patel
 
Simple chat room using python
Simple chat room using pythonSimple chat room using python
Simple chat room using pythonVISHAL VERMA
 
VTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION) SOLVED PAPERS
VTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION)  SOLVED PAPERSVTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION)  SOLVED PAPERS
VTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION) SOLVED PAPERSvtunotesbysree
 
Android technical quiz app
Android technical quiz appAndroid technical quiz app
Android technical quiz appJagdeep Singh
 
Flutter presentation.pptx
Flutter presentation.pptxFlutter presentation.pptx
Flutter presentation.pptxFalgunSorathiya
 
Quiz app android ppt
Quiz app android pptQuiz app android ppt
Quiz app android pptAditya Nag
 
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?Katy Slemon
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPTkamal kotecha
 
Lan chat system
Lan chat systemLan chat system
Lan chat systemWipro
 
KaGemCo - Mobile Recharge System
KaGemCo - Mobile Recharge SystemKaGemCo - Mobile Recharge System
KaGemCo - Mobile Recharge SystemPanos Gemos
 
Distributed System-Multicast & Indirect communication
Distributed System-Multicast & Indirect communicationDistributed System-Multicast & Indirect communication
Distributed System-Multicast & Indirect communicationMNM Jain Engineering College
 

Tendances (20)

Social messenger introduction
Social messenger introductionSocial messenger introduction
Social messenger introduction
 
Telnet
TelnetTelnet
Telnet
 
Chat Room System using Java Swing
Chat Room System using Java SwingChat Room System using Java Swing
Chat Room System using Java Swing
 
How to build a chat application with react js, nodejs, and socket.io
How to build a chat application with react js, nodejs, and socket.ioHow to build a chat application with react js, nodejs, and socket.io
How to build a chat application with react js, nodejs, and socket.io
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming Tutorial
 
Simple chat room using python
Simple chat room using pythonSimple chat room using python
Simple chat room using python
 
VTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION) SOLVED PAPERS
VTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION)  SOLVED PAPERSVTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION)  SOLVED PAPERS
VTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION) SOLVED PAPERS
 
Android technical quiz app
Android technical quiz appAndroid technical quiz app
Android technical quiz app
 
Application Layer
Application Layer Application Layer
Application Layer
 
TELNET Protocol
TELNET ProtocolTELNET Protocol
TELNET Protocol
 
Dhcp ppt
Dhcp pptDhcp ppt
Dhcp ppt
 
Flutter presentation.pptx
Flutter presentation.pptxFlutter presentation.pptx
Flutter presentation.pptx
 
Quiz app android ppt
Quiz app android pptQuiz app android ppt
Quiz app android ppt
 
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
How to Build Real-time Chat App with Express, ReactJS, and Socket.IO?
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Lan chat system
Lan chat systemLan chat system
Lan chat system
 
KaGemCo - Mobile Recharge System
KaGemCo - Mobile Recharge SystemKaGemCo - Mobile Recharge System
KaGemCo - Mobile Recharge System
 
Flutter Intro
Flutter IntroFlutter Intro
Flutter Intro
 
Distributed System-Multicast & Indirect communication
Distributed System-Multicast & Indirect communicationDistributed System-Multicast & Indirect communication
Distributed System-Multicast & Indirect communication
 

Similaire à Multi user chat system using java

Client server chat application
Client server chat applicationClient server chat application
Client server chat applicationPiyush Rawat
 
Mail Server Project Report
Mail Server Project ReportMail Server Project Report
Mail Server Project ReportKavita Sharma
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptxEliasPetros
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theoryMukesh Tekwani
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
Networking in java, Advanced programming
Networking in java, Advanced programmingNetworking in java, Advanced programming
Networking in java, Advanced programmingGera Paulos
 
How a network connection is created A network connection is initi.pdf
How a network connection is created A network connection is initi.pdfHow a network connection is created A network connection is initi.pdf
How a network connection is created A network connection is initi.pdfarccreation001
 
Java Networking
Java NetworkingJava Networking
Java NetworkingSunil OS
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagarNitish Nagar
 
Linux Inter Process Communication
Linux Inter Process CommunicationLinux Inter Process Communication
Linux Inter Process CommunicationAbhishek Sagar
 
Network Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxNetwork Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxssuser23035c
 
04 android
04 android04 android
04 androidguru472
 

Similaire à Multi user chat system using java (20)

Client server chat application
Client server chat applicationClient server chat application
Client server chat application
 
Mail Server Project Report
Mail Server Project ReportMail Server Project Report
Mail Server Project Report
 
28 networking
28  networking28  networking
28 networking
 
Sockets
SocketsSockets
Sockets
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptx
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theory
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Networking in java, Advanced programming
Networking in java, Advanced programmingNetworking in java, Advanced programming
Networking in java, Advanced programming
 
Java socket programming
Java socket programmingJava socket programming
Java socket programming
 
How a network connection is created A network connection is initi.pdf
How a network connection is created A network connection is initi.pdfHow a network connection is created A network connection is initi.pdf
How a network connection is created A network connection is initi.pdf
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
Advanced Java Topics
Advanced Java TopicsAdvanced Java Topics
Advanced Java Topics
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
 
A.java
A.javaA.java
A.java
 
Java seminar.pptx
Java seminar.pptxJava seminar.pptx
Java seminar.pptx
 
Linux Inter Process Communication
Linux Inter Process CommunicationLinux Inter Process Communication
Linux Inter Process Communication
 
Network Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxNetwork Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptx
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
Socket
SocketSocket
Socket
 
04 android
04 android04 android
04 android
 

Dernier

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Dernier (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Multi user chat system using java

  • 1. Multi User Chat System Using Java
  • 2. • Multi User Chat System is an application through which the user can communicate with other users connected in the same network area (LAN). This works under any operating system and is programmed in java. • To establish a communication between the systems, we need simple socket connections in order to connect them in a network. • Socket programming uses the client socket and server socket methods to connect the local host to the named host and port
  • 3. • The communication between various users is done using server client model. • Several client machines are connected to their dedicated server ports and communication is established. • We use the lowest level of networking techniques available in java, though there are many ways of connecting client with the server. • Hence, we need simple classes of networking package in order to establish a server client prototype.
  • 4. What is a server?? • A server is a system (software and suitable computer hardware) that responds to requests across a computer network to provide, or help to provide, a network service. • Servers can be run on a dedicated computer, but many networked computers are capable of hosting servers. In many cases, a computer can provide several services and have several servers running. • Servers are computer programs running to serve the requests of other programs, the clients. Thus, the server performs some task on behalf of clients. The clients typically connect to the server through the network but may run on the same computer. In the context of Internet Protocol (IP) networking, a server is a program that operates as a socket listener.
  • 5.
  • 6. Client: Client is a user system which uses its server to get its program or action executed.
  • 7. • To have a basic server client connection through java programming language, we need the concepts of java as such as, • 1. Network packages • 2. Thread classes • 3. AWT tool kit • 4. Event handling.
  • 8.
  • 9. Step by step modules… * Listener class * While-Accept loop * Per-Thread class * While-Read/Write loop (Server side) * Removing dead connections * Client class * While-Read/Write loop (Client side)
  • 10. 1.What does the server do? - Stand alone program (JVM) 2.Listening to a port After a server is ready, get ready to receive incoming connections. 3. Sockets - Communications pass through sockets. Socket has an InputStream and an OutputStream.
  • 11. • PORT // Constructor and while-accept loop all in one. public Server( int port ) throws IOException { // All we have to do is listen listen( port ); } SERVER // start listening on the port ServerSocket ss = new ServerSocket( port ); // loop forever while (true) { // get a connection Socket newSocket = ss.accept(); // deal with the connection
  • 12. The main() routine // Main routine // Usage: java Server >port< static public void main( String args[] ) throws Exception { // Get the port # from the command line int port = Integer.parseInt( args[0] ); // Create a Server object, which will automatically begin // accepting connections. new Server( port );
  • 13. 4.Serialization of incoming requests - multithreading.
  • 14. private void listen( int port ) throws IOException { // Create the ServerSocket ss = new ServerSocket( port ); // Tell the world we're ready to go System.out.println( "Listening on "+ss ); // Keep accepting connections forever while (true) { // Grab the next incoming connection Socket s = ss.accept(); // Tell the world we've got it System.out.println( "Connection from "+s ); // Create a DataOutputStream for writing data to the // other side DataOutputStream dout = new DataOutputStream( s.getOutputStream() ); // Save this stream so we don't need to make it again outputStreams.put( s, dout ); // Create a new thread for this connection, and then forget // about it new ServerThread( this, s ); } }
  • 15. 5. The communications protocol * When a user types something into their chat window, their message will be sent as a string through a DataOutputStream. * When the server receives a message, through a DataInputStream, it will send this same message to all users, again as a string through a DataOutputStream. * The users will use a DataInputStream to receive the message.
  • 16. 6. Removing dead connections // The connection is closed for one reason or another, // so have the server dealing with it server.removeConnection( socket );
  • 17. Now, to the client side 1. Use an interface. 2. Connect to the server // Connect to the server try { // Initiate the connection socket = new Socket( host, port ); // We got a connection! Tell the world System.out.println( "connected to "+socket ); // Let's grab the streams and create DataInput/Output streams // from them din = new DataInputStream( socket.getInputStream() ); dout = new DataOutputStream( socket.getOutputStream() ); // Start a background thread for receiving messages new Thread( this ).start(); } catch( IOException ie ) { System.out.println( ie ); } }
  • 18. The While-Read/Write loop (Client side) // Background thread runs this: show messages from other window public void run() { try { // Receive messages one-by-one, forever while (true) { // Get the next message String message = din.readUTF(); // Print it to our text window ta.append( message+"n" ); } } catch( IOException ie ) { System.out.println( ie ); } }
  • 19. Pretty simple. Each incoming message gets displayed in the text display window, and then the loop goes back to waiting for the next message. Limitations: Cant add a new client when a communication is under process.