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