2013-08-26 78 views
2

我有簡單的UDP服務器/客戶端程序,我轉發我的端口和服務器通過互聯網接收和發送數據包,但遠程機器上的客戶端不能接收它們,所以即時通訊想知道如何接收在客戶端沒有轉發端口的數據包(如果它甚至可能)?如果不可能,我該如何讓客戶端通過互聯網接收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(); 

       } 

回答