我試圖從UDP端口6610讀取所有流量,並且我可以在Wireshark中看到數據包。我給這個簡單的讀者:簡單的UDP閱讀器
public class ReceiveUDP extends Thread {
private int port = 6610;
private byte[] buffer = new byte[256];
private DatagramSocket socket;
private DatagramPacket packet;
public ReceiveUDP() throws SocketException {
socket = new DatagramSocket(port);
packet = new DatagramPacket(buffer, buffer.length);
System.out.println("Succesfull socket/packet creation");
}
@Override
public void run() {
try {
socket.receive(packet);
System.out.println("Succeded!");
} catch (IOException e) {
System.out.println("Failed to receive packet"+e.getCause().getMessage());
}
}
public static void main(String[] args) throws SocketException {
new ReceiveUDP().start();
}
打印輸出是:
Succesfull socket/packet creation
即該腳本鎖定在socket.receive(packet)
。 我錯過了什麼嗎?
你如何發送數據包?換句話說:*你期望它得到什麼*? –
您是否期望接收單播或廣播UDP數據包? –
@Joachim - 我是UDP的新手 - 我必須*發送*什麼東西才能接收內容?我希望收到在這個端口發送的一切...... – Theodor