-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClient.java
More file actions
71 lines (66 loc) · 1.95 KB
/
Copy pathClient.java
File metadata and controls
71 lines (66 loc) · 1.95 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.*;
import java.util.Scanner;
import java.net.*;
class Client{
public static void main(String[] args) {
MyFrame frame=new MyFrame("Client Window ");
try{
Socket s=new Socket("localhost",6666);
DataInputStream dis=new DataInputStream(s.getInputStream());
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
Scanner sc=new Scanner(System.in);
String send="";
String Exit="start";
boolean flag;
// frame.setFlag(true);
FileWriter br=new FileWriter("log/file_"+System.currentTimeMillis()+".txt",true);
while(!Exit.equals("bye")){
do{
// frame.setFlag(true);
send=frame.getString();
int count=0;
while(send.length()==0){
send=frame.getString();
if(send.equals("****")){
System.exit(0);
}
Thread.sleep(1000);
// if(count>=10)
send="over";
// count+=1;
}
if(send.equals("bye")){
break;
}
if(!send.equals("over"))
br.write("YOU :"+send+"\n");
dout.writeUTF(send);
dout.flush();
}while(!send.equals("over"));
Exit=send;
if(send.equals("bye")){
break;
}
String str=(String)dis.readUTF();
while(!str.equals("over")){
// frame.setFlag(false);
// System.out.println("Server send: "+str);
if(str.equals("bye")){
break;
}
frame.addString(str);
br.write("PERSON: "+str+"\n");
str=(String)dis.readUTF();
// System.out.println("reading...");
}
Exit=str;
}
dout.close();
s.close();
br.close();
// frame.setNull();
}catch(Exception e){
System.out.println(e);
}
}
}