1
我嘗試從Java中的X-Plane 12中讀取UDP流。 這是我嘗試:Java中用於從X-Plane獲取數據的UDP客戶端12
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飛機正在運行和UDP選項被激活 - 但我的程序會在控制檯上打印任何..它運行過程中出現永遠(而真)
爲什麼被封鎖? X-Plane正在運行,其UDP Socket在端口49000上運行 - 數據包被丟棄? O_o不要丟棄durka durk!問題在哪裏? – Suisse
發送發生在接收之前。沒有人可以發送。 嘗試把你的監聽while循環插入一個新的線程,這是初始化之前你調用socket.send() –