-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeDeadMsg.java
More file actions
48 lines (41 loc) · 1.1 KB
/
Copy pathHomeDeadMsg.java
File metadata and controls
48 lines (41 loc) · 1.1 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
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.SocketException;
public class HomeDeadMsg implements Msg{
int msgType = Msg.HOME_DEAD_MSG;
TankClient tc;
public HomeDeadMsg(TankClient tc){
this.tc=tc;
}
public HomeDeadMsg(){
}
@Override
public void send(DatagramSocket ds, String IP, int udpPort) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
try {
dos.writeInt(msgType);
} catch (IOException e) {
e.printStackTrace();
}
byte[] buf = baos.toByteArray();
try {
DatagramPacket dp = new DatagramPacket(buf, buf.length,
new InetSocketAddress(IP, udpPort));
ds.send(dp);
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void parse(DataInputStream dis) {
tc.home.setLive(false);
}
}