Assignment 3
Assignment 3
Code:
ClientTwo.java
package Multi_Client_Chat;
import java.io.*;
import java.net.*;
import java.util.*;
/**
* @author Karan
*/
try{
InetAddress ip=InetAddress.getByName("localhost");
while(true){
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(dis.readUTF());
dos.writeUTF(tosend);
if(tosend.equals("Exit"))
s.close();
System.out.println("Connection closed");
break;
System.out.println(received);
scan.close();
dis.close();
dos.close();
catch(Exception e)
e.printStackTrace();
Subject: MCA L502 [Choice Based] Open Source System for ADC Lab Nov 2020
SIES College of Management Studies TYMCA, Sem-V, Roll No : 24
ServerTwo.java
package Multi_Client_Chat;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
/**
* @author Karan
*/
while(true){
Socket s=null;
try{
s =ss.accept();
Subject: MCA L502 [Choice Based] Open Source System for ADC Lab Nov 2020
SIES College of Management Studies TYMCA, Sem-V, Roll No : 24
t.start();
catch(Exception e)
s.close();
e.printStackTrace();
final Socket s;
Subject: MCA L502 [Choice Based] Open Source System for ADC Lab Nov 2020
SIES College of Management Studies TYMCA, Sem-V, Roll No : 24
this.s = s;
this.dis = dis;
this.dos = dos;
@Override
String received;
String toreturn;
while (true)
try {
received = dis.readUTF();
if(received.equals("Exit"))
this.s.close();
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("Connection closed");
break;
switch (received) {
case "Date" :
toreturn = fordate.format(date);
dos.writeUTF(toreturn);
break;
case "Time" :
toreturn = fortime.format(date);
dos.writeUTF(toreturn);
break;
default:
dos.writeUTF("Invalid input");
break;
} catch (IOException e) {
e.printStackTrace();
try
Subject: MCA L502 [Choice Based] Open Source System for ADC Lab Nov 2020
SIES College of Management Studies TYMCA, Sem-V, Roll No : 24
this.dis.close();
this.dos.close();
}catch(IOException e){
e.printStackTrace();
Output:
Server
Client-1
Subject: MCA L502 [Choice Based] Open Source System for ADC Lab Nov 2020
SIES College of Management Studies TYMCA, Sem-V, Roll No : 24
Server
Client-2
Client-1
Subject: MCA L502 [Choice Based] Open Source System for ADC Lab Nov 2020
SIES College of Management Studies TYMCA, Sem-V, Roll No : 24
Server
Client-2
Subject: MCA L502 [Choice Based] Open Source System for ADC Lab Nov 2020
SIES College of Management Studies TYMCA, Sem-V, Roll No : 24
Server
Subject: MCA L502 [Choice Based] Open Source System for ADC Lab Nov 2020