2
votes

I have simple UDP server/client program, I forwarded my ports and server receives and sends packets via internet,but the client on the remote machine cant receive them,so im wondering how to receive packets without forwarding ports on client side(if its even possible)? And if its not possible , what should i do to make client to receive UDP packets via internet?

Client receive thread looks like this :

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();

              }
1

1 Answers

0
votes

You don't need to do port forwarding for the client side, NAT takes care of that automatically. http://en.wikipedia.org/wiki/Network_address_translation Your client might not be reachable for different reasons (firewall, etc.).