-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnection.java
More file actions
52 lines (43 loc) · 1.19 KB
/
Connection.java
File metadata and controls
52 lines (43 loc) · 1.19 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
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
public class Connection {
String serverIp;
int serverPort;
private Socket socket;
private DataInputStream input;
private DataOutputStream output;
Connection(String serverIp, int serverPort){
this.serverIp = serverIp;
this.serverPort = serverPort;
}
public Boolean startConnection() throws IOException{
try{
socket = new Socket(this.serverIp, this.serverPort);
input = new DataInputStream(socket.getInputStream());
output = new DataOutputStream(socket.getOutputStream());
return true;
}catch(Exception io){
return false;
}
}
public Socket getSocket(){
return socket;
}
public DataInputStream getInput(){
return input;
}
public DataOutputStream getOutObject(){
return output;
}
public void closeConnection(){
try {
input.close();
output.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}