-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiPhoneListener.java
More file actions
60 lines (52 loc) · 1.36 KB
/
iPhoneListener.java
File metadata and controls
60 lines (52 loc) · 1.36 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
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.UnknownHostException;
public class iPhoneListener {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("iPhoneListener");
DatagramSocket socket = null;
FileWriter fwriter = null;
PrintWriter pwriter = null;
try {
// sock = new Socket("10.0.2.1", 10552);
// get a datagram socket
socket = new DatagramSocket(5169);
fwriter = new FileWriter("locLog.csv");
pwriter = new PrintWriter(fwriter);
// send request
byte[] buf = new byte[256];
// get response
DatagramPacket packet = new DatagramPacket(buf, buf.length);
while (1==1) {
socket.receive(packet);
if (packet.getLength() > 0) {
// display response
String received = new String(packet.getData(), 0, packet.getLength());
System.out.print(received );
pwriter.print(received);
}
}
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
if (socket != null)
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
if (socket != null)
socket.close();
}
finally {
if (socket != null)
socket.close();
}
}
}