我有简单的UDP服务器/客户端程序,我转发了我的端口,服务器通过互联网接收和发送数据包,但是远程机器上的客户端无法接收它们,所以我想知道如何在客户端不转发端口的情况下接收数据包(如果它甚至可能的)?如果不可能,我应该怎么做才能让客户端通过互联网接收 UDP 数据包?
客户端接收线程如下所示:
public void run(){
DatagramSocket serverSocket = null;
while(true){
try {
serverSocket = new DatagramSocket(7000+clientNumber+100);
} catch (SocketException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
byte[] receiveData = new byte[1024];
DatagramPacket receiveX = new DatagramPacket(receiveData, receiveData.length);
try {
serverSocket.receive(receiveX);
} catch (IOException e) {
System.out.println("Nepagavau paketo");
}
String korX = new String( receiveX.getData());
Play.priesoX = Float.parseFloat(korX);
serverSocket.close();
}