Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerThread.java
More file actions
Latest commit
45 lines (34 loc) · 963 Bytes
/
Copy pathServerThread.java
File metadata and controls
45 lines (34 loc) · 963 Bytes
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
importjava.net.DatagramPacket;
importjava.net.DatagramSocket;
importjava.net.Inet4Address;
importjava.net.InetAddress;
publicclassServerThreadextendsThread {
DatagramSocketsocket;
Stringmsg;
byte[] msgByte;
InetAddresshost;
intserverSocket;
DatagramPacketrequest;
publicServerThread(){
init();
}
publicvoidinit(){
try{
socket = newDatagramSocket();
host = InetAddress.getByName("localhost");
//can be between 5800 and 5810
serverSocket = 5803;
}catch(Exceptione){
System.out.println("Error: + " + e);
}
}
publicvoidsendInfo(booleantargetFound, doubleangle, doubledistance){
msg = String.valueOf(targetFound) + ";" + String.valueOf(angle) + ";" + String.valueOf(distance);
msgByte = msg.getBytes();
try{
request = newDatagramPacket(msgByte, msgByte.length, host, serverSocket);
socket.send(request);
}catch(Exceptione){
System.out.println("Error: " + e);
}
}