NAT punch through with UDP
I'm trying to implement a NAT Punch-Through system where in clients can connect to each other without users needing to port forward. However, I've come across some problems with which I'm hoping someone may be able to help me with. I'll try my best to describe the situation and problem.
Essentially, I have two java applications; a server and a client. In order to test the system, I run two instances of the client and one of the server. The client can run in one of two modes, as it can either 'host' a session or 'join' a session. When testing the system, I have one client host and one join. What I'm attempting to do is have the server 'introduce' the two clients so that they can freely communicate without the server, but more importantly without the user having to do any port forwarding.
So far, I've got to the stage where the clients can connect to the server, while the hosting client is able to upload its information to the server and this information is passed on to the second client when it connects. The server is able to freely communicate with the client, without the need of any port forwarding on the clients end. However, my problems begin when I attempt to connect from one client to another (using the same socket that was used to contact the server). Despite each client having one anothers information, the packets never seem to get through. What I'm doing is having the server obtain the IP/PORT for both clients using packet.getAddress() and packet.getPort(), but when the clients send packets to each other, they are never received.
The second client attempting to receive the packet from the hosting client does so like this:
While the hosting client sends the packet like this:
DatagramPacket receiver = new DatagramPacket(new byte,1024,this.host_ip,this.host_port);
String ping = (new String(receiver.getData())).trim();
I'm not really sure where I'm going wrong and I'd really appreciate any help available. Maybe there's something wrong in the architecture that I'm trying to implement, although to me it seems fine.
send = "ping".getBytes();
DatagramPacket sendPacket = new DatagramPacket(send,send.length,ip,port);