-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiClientThread.java
45 lines (39 loc) · 1.61 KB
/
MultiClientThread.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
package networkAssignment;
public class MultiClientThread extends Thread{
private MultiClient mc;
public MultiClientThread(MultiClient mc){
this.mc = mc;
}
public void run(){
String message = null;
String[] receivedMsg = null;
boolean isStop = false;
while(!isStop){
try{
message = (String)mc.getOis().readObject();
receivedMsg = message.split("#");
}catch(Exception e){
e.printStackTrace();
isStop = true;
}
if(receivedMsg[1].equals("ENTERED")) {
mc.getJta().append("--------- " + receivedMsg[0] + "님이 입장했습니다. ---------\n"+ System.getProperty("line.separator"));
mc.getJta().setCaretPosition(
mc.getJta().getDocument().getLength());
} else if(receivedMsg[1].equals("LEFT")){
if(receivedMsg[0].equals(mc.getId())){
mc.exit();
}else{
mc.getJta().append("--------- " + receivedMsg[0] +"님이 퇴장했습니다. ---------\n"+ System.getProperty("line.separator"));
mc.getJta().setCaretPosition(
mc.getJta().getDocument().getLength());
}
}else{
mc.getJta().append(
receivedMsg[0] +" : "+receivedMsg[1]+System.getProperty("line.separator"));
mc.getJta().setCaretPosition(
mc.getJta().getDocument().getLength());
}
}
}
}