UDP Server listens only to localhost and not over Internet

I Am testing a UDP Server/Client code on a small test game so i can apply the principles on my real project, but it seems like the server only listens to the localhost or 127.0.0.1 , but when I change the InetAddress to my IP, the server won’t listen to any packets .
is the router firewall dropping the packets ?
is the OS firewall dropping the packets ?
if so how to make this window popup like other multiplayers games that uses udp ?

http://img11.hostingpics.net/pics/689160Windows7Firewall04.png

I have read that i need udp hole punching so i can access through firewall , if true then how ?
Server Class


public class GameServer extends Thread  {
private DatagramSocket socket;
private mainclass mc;
public GameServer(mainclass mc) {
    this.mc = mc;
    try {
        this.socket = new DatagramSocket(6500);

    } catch (SocketException e) {
        e.printStackTrace();
    }
}
public void run() {
    while (true) {
        byte[] data = new byte[1024];
        DatagramPacket packet = new DatagramPacket(data, data.length);
        try {
            socket.receive(packet);
        } catch (IOException e) {
            e.printStackTrace();
        }  
       String msg=new String(packet.getData());
       System.out.println(msg);
    }
}

Client Class


public class GameClient extends Thread {

private InetAddress ipAddress;
private DatagramSocket socket;
private mainclass mc;

public GameClient(mainclass mc, String ipAddress) {
    this.mc = mc;
    try {
        this.socket = new DatagramSocket();
        this.ipAddress = InetAddress.getByName(ipAddress);
    } catch (SocketException e) {
        e.printStackTrace();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
}

public void run() {
    while (true) {
        byte[] data = new byte[1024];
        DatagramPacket packet = new DatagramPacket(data, data.length);
        try {
            socket.receive(packet);
            sendData("PING".getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

public void sendData(byte[] data  ) {

        DatagramPacket packet = new DatagramPacket(data, data.length, ipAddress, 6500);
        try {
            this.socket.send(packet);
        } catch (IOException e) {
            e.printStackTrace();
        }
   }
}

i have this problem with TCP as well,

you can enter the settings in you router, and look for the tab of networks o where you can check what are your networks and port forwarding…

you need to enable the port and the ip the server is using:

here’s an example:
http://www.4shared.com/photo/3va9ED8-ba/Screen_Shot_2015-11-30_at_1433.html

I think i need to use an automatic port forwarding methode so any player behind a NAT can host a server easily and won’t open his router configuration everytime he needs to open a certain port so id use UPnP (Universal Plug And Play) there is a plenty UPnP librarys in java for that including weupnp and cling and i have no idea how to use them sadly :clue: ???
i saw this topic with some code example but all the links are dead … :-\ http://www.java-gaming.org/index.php?topic=22088.0

UPnP is disabled on many routers by default.

The most rudimentary usage for cling is covered in their FAQ:

http://4thline.org/projects/cling/support/manual/cling-support-manual.html#section.PortMapping

As for users who have upnp disabled, that’s their problem.
Code to support it, and document the necessary port forwardings for those who have it disabled.