-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.java
46 lines (45 loc) · 1.64 KB
/
Client.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.net.*;
import java.io.*;
class ClientSystem{
String str;
ClientSystem()throws Exception{
System.out.print("\033[2J\033[1H");
String cSender="\033[32m";
String cReceiver="\033[35m";
String fColor="\033[36m";
String cStop="\033[0m";
Socket s=new Socket("127.0.1.1",2001);
System.out.println(fColor+"\t\tCHAT APPLICATION"+cStop+"\nClient started...");
System.out.println("---Enter ## at the last line of message to send");
System.out.println("---Enter $$ to stop the chat");
BufferedReader brSend=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw=new PrintWriter(s.getOutputStream());
BufferedReader brReceive=new BufferedReader(new InputStreamReader(s.getInputStream()));
do{
System.out.print("\t\t -----------------------------\n\t\t|");
System.out.println(cReceiver+"You : "+cStop);
do{
System.out.print("\t\t| ");
str=brSend.readLine();
pw.write(str+"\n");
}while(!str.equals("##")&&!str.equals("$$"));
pw.flush();
System.out.println("\t\t -----------------------------");
if(str.equals("$$")) break;
str=brReceive.readLine();
System.out.print(" -^------------------------\n|");
System.out.println(cSender+"Server : "+cStop);
while(!str.equals("##")&&!str.equals("$$")){
System.out.println("| "+str);
str=brReceive.readLine();
}
System.out.println(" --------------------------");
if(str.equals("$$")) break;
}while(true);
}
}
class Client{
public static void main(String args[])throws Exception{
ClientSystem s=new ClientSystem();
}
}