-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultithreadedClient.java
More file actions
executable file
·162 lines (127 loc) · 4.01 KB
/
MultithreadedClient.java
File metadata and controls
executable file
·162 lines (127 loc) · 4.01 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package Client;
import java.awt.List;
import java.io.*;
import java.net.Socket;
import java.util.*;
/**
* Created by amirpez on 11/11/17.
*/
public class MultithreadedClient extends Thread implements ImpMultithreadedClient {
private Socket clientSocket;
private BufferedReader dis;
private PrintWriter dos;
private Controller controller;
private User user;
private boolean shouldRun = true;
private boolean loginAccessBoolean;
private ArrayList<String> allUsers;
private java.util.List<String> onlineUsers ;
private ArrayList<String> userRecievedMesseges;
private String pm = null ;
private boolean isOnlineListUpdated = true ;
// private ClientGUI gui;
public void setPm(String pm) {
this.pm = pm;
}
public MultithreadedClient(Socket clientSocket, Client client) {
this.clientSocket = clientSocket;
this.controller = new Controller(this);
this.allUsers = new ArrayList<>();
this.onlineUsers = new ArrayList<>();
this.userRecievedMesseges = new ArrayList<>();
}
public String getPm() {
return pm;
}
public java.util.List<String> getOnlineUsers() {
return onlineUsers;
}
public boolean isLoginAccessBoolean() {
return loginAccessBoolean;
}
public void setLoginAccessBoolean(boolean loginAccessBoolean) {
this.loginAccessBoolean = loginAccessBoolean;
}
public boolean isOnlineListUpdated() {
return isOnlineListUpdated;
}
public void setOnlineListUpdated(boolean onlineListUpdated) {
isOnlineListUpdated = onlineListUpdated;
}
@Override
public void run() {
try {
dos = new PrintWriter(clientSocket.getOutputStream());
dis = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
while (shouldRun) {
try {
// while (dis.available() == 0) {
// try {
// Thread.sleep(1);
// } catch (Exception e) {
// System.out.println("Problem1 , Class MultiThreadedCient , Method >> run() ");
// }
// }
} catch (Exception e) {
System.out.println("Problem2 , Class MultiThreadedCient , Method >> run() ");
}
controller.identifier(getFromServer());
}
controller.identifier(getFromServer());
} catch (Exception e) {
System.out.println("Problem3 , Class MultiThreadedCient , Method >> run() ");
}
}
public String getFromServer() {
try {
return dis.readLine();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public void sendStringToServer(String text) {
try {
dos.write(text);
dos.flush();
} catch (Exception e){
System.out.println("DavoodMouseDare");
}
}
public void setAllUsers(String str) {
this.allUsers.add(str);
}
public void setOnlineUsers(String str){
this.onlineUsers.add(str);
}
public void clearOnlineUsers(){
this.onlineUsers.clear();
}
public java.util.List<String> getAllUsers() {
return allUsers;
}
public void close() {
try {
dis.close();
dos.close();
clientSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void makeUser(String username, String user) {
User user1 = new User(username, user);
this.user = user1;
}
public User getUser() {
return user;
}
public void pmHandler(String str1 , String str2){
this.pm = str1 + " : " + str2 ;
}
public String pmHandlerChat(String pm, String from) {
String messege = from + " : " + pm;
userRecievedMesseges.add(messege);
return messege;
}
}