我尝试用Java从X-Plane 12读取UDP流。 这是我尝试的:
public class EchoClient {
@Test
public void echo() throws IOException {
DatagramSocket socket;
InetAddress address;
byte[] buf;
socket = new DatagramSocket();
address = InetAddress.getByName("localhost");
String msg = "TEST";
buf = msg.getBytes();
DatagramPacket packet
= new DatagramPacket(buf, buf.length, address, 49000);
socket.send(packet);
packet = new DatagramPacket(buf, buf.length);
System.out.println("hi there");
while(true) {
socket.receive(packet); // it "stops" here... without an error
String received = new String(
packet.getData(), 0, packet.getLength());
System.out.println(received);
}
}}
X-Plane正在运行且UDP选项已激活 - 但我的程序在控制台上没有打印任何内容..它永远是runnig(同时为true)
答案 0 :(得分:0)
接收被阻止并等待接收数据包。您之前发送的数据包将丢弃在地板上,因为没有人正在收听。