0% found this document useful (0 votes)
6 views

Assignment 2

Uploaded by

Karan Margaje
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Assignment 2

Uploaded by

Karan Margaje
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

SIES College of Management Studies TYMCA, Sem-V, Roll No : 24

2. Create a Chat application between a CLient and Server . The application must
continuously send/receive messages from the Client/Server until the Client types "Exit"

Code:

ClientOne.java

package client_server_program;

import java.io.*;

import java.net.*;

/**

* @author Karan

*/

public class ClientOne {

public static void main(String args[]){

try

Socket s = new Socket("localhost", 888);

DataOutputStream dos = new DataOutputStream( s.getOutputStream());

BufferedReader br = new BufferedReader( new InputStreamReader(


s.getInputStream()));

BufferedReader kb = new BufferedReader( new InputStreamReader(System.in));

String str, str1;

while (!(str = kb.readLine()).equals("exit")) {

dos.writeBytes(str + "\n");

str1 = br.readLine();

Subject: MCA L502 [Choice Based] Open Source System for ADC Lab Nov 2020
SIES College of Management Studies TYMCA, Sem-V, Roll No : 24

System.out.println(str1);

dos.close();

br.close();

kb.close();

s.close();

catch(IOException ex)

System.out.println(ex);

ServerOne.java

package client_server_program;

import java.io.*;

import java.net.*;

import java.util.logging.Level;

import java.util.logging.Logger;

/**

* @author Karan

Subject: MCA L502 [Choice Based] Open Source System for ADC Lab Nov 2020
SIES College of Management Studies TYMCA, Sem-V, Roll No : 24

*/

public class ServerOne {

public static void main(String args[]){

try {

ServerSocket ss = new ServerSocket(888);

Socket s = ss.accept();

System.out.println("Connection established");

PrintStream ps= new PrintStream(s.getOutputStream());

BufferedReader br= new BufferedReader(new


InputStreamReader(s.getInputStream()));

BufferedReader kb= new BufferedReader(new InputStreamReader(System.in));

while (true) {

String str, str1;

while ((str = br.readLine()) != "exit") {

System.out.println(str);

str1 = kb.readLine();

ps.println(str1);

Subject: MCA L502 [Choice Based] Open Source System for ADC Lab Nov 2020
SIES College of Management Studies TYMCA, Sem-V, Roll No : 24

ps.close();

br.close();

kb.close();

ss.close();

s.close();

System.exit(0);

} catch (IOException ex) {

System.out.println(ex);

Output:

Subject: MCA L502 [Choice Based] Open Source System for ADC Lab Nov 2020
SIES College of Management Studies TYMCA, Sem-V, Roll No : 24

Subject: MCA L502 [Choice Based] Open Source System for ADC Lab Nov 2020
SIES College of Management Studies TYMCA, Sem-V, Roll No : 24

Subject: MCA L502 [Choice Based] Open Source System for ADC Lab Nov 2020

You might also like