-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientSession.java
More file actions
65 lines (55 loc) · 1.67 KB
/
Copy pathClientSession.java
File metadata and controls
65 lines (55 loc) · 1.67 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
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.Socket;
public class ClientSession {
private String sessionId;
private Socket clientSocket;
private DatagramSocket clientDatagramSocket;
private DatagramPacket initialPacket;
// Other session data
public ClientSession(String sessionId, DatagramSocket clientDatagramSocket, DatagramPacket initialPacket) {
this.sessionId = sessionId;
this.clientDatagramSocket = clientDatagramSocket;
this.initialPacket = initialPacket;
}
public ClientSession(String sessionId, Socket clientSocket) {
this.sessionId = sessionId;
this.clientSocket = clientSocket;
}
public String connectionType() {
if (clientSocket != null) {
return "TCP";
}
if (clientDatagramSocket != null & initialPacket != null) {
return "UDP";
}
else {
System.out.println("Error: ");
return "Error";
}
}
public DatagramPacket getInitialPacket() {
return initialPacket;
}
public boolean isConnected() {
return clientSocket.isConnected();
}
public String getSessionId() {
return sessionId;
}
public Socket getClientSocket() {
return clientSocket;
}
public DatagramSocket getClientDatagramSocket() {
return clientDatagramSocket;
}
public void close() throws IOException {
if (clientSocket != null) {
clientSocket.close();
}
if (clientDatagramSocket != null) {
clientDatagramSocket.close();
}
}
}