-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkClientV5.java
More file actions
50 lines (39 loc) · 1.24 KB
/
Copy pathNetworkClientV5.java
File metadata and controls
50 lines (39 loc) · 1.24 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
package exception.ex4;
import exception.ex4.exception.ConnectExceptionV4;
import exception.ex4.exception.SendExceptionV4;
public class NetworkClientV5 implements AutoCloseable{
private final String address;
public boolean connectError;
public boolean sendError;
public NetworkClientV5(String address) {
this.address = address;
}
public void connect(){
if(connectError){
throw new ConnectExceptionV4(address, address + " 서버 연결 실패 ");
}
System.out.println(address + " 서버 연결 성공");
}
public void send(String data){
if(sendError){
throw new SendExceptionV4(data, address + " 서버에 데이터 전송 실패 " + data);
}
System.out.println(address + "서버에 데이터 전송 : " + data);
}
public void disconnect() {
System.out.println(address + " 서버 연결 해제 ");
}
public void initError(String data){
if(data.contains("error1")){
connectError = true;
}
if(data.contains("error2")){
sendError = true;
}
}
@Override
public void close(){
System.out.println("NetworkClientV5.close");
disconnect();
}
}