Ex 3.b - Chat Application
Ex 3.b - Chat Application
Aim:
Algorithm:
Server Side:
Step -3: Under ChatServer class, create a server socket to communicate with the client
using ServerSocket() constructor.
Step – 4: Accept the request from the client using accept() method.
Step – 5: Establish socket connection between client and server using BufferedReader.
Step -6: Send and receive messages to and from client using getInputStream() and
getOutputStream().
Client Side:
Step - 1: Start.
Step - 3: Under ChatClient class, create a new socket with IP address of the server system
using Socket() constructor.
Step – 4: Establish socket connection between client and server using BufferedReader.
Step - 5: Send and receive messages to and from client using getInputStream() and
getOutputStream().
import java.io.*;
import java.net.*;
while(true)
System.out.println(receiveMessage);
sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
pwrite.flush();
ChatClient.java
import java.io.*;
import java.net.*;
while(true)
sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
pwrite.flush();
System.out.println(receiveMessage);
Output:
Result:
Thus the Java program to implement Chat application using Client Server Communication is
written, executed and the output is verified.