TCP/IP works as follows:
When you create a connection between client and server, it connects to a port based on port and ip address.
Your ip address is the ip address given by the server, and the port is anything given by the party that initiates the connection. For example, an FTP server will connect to port 21 unless the server specifically mentions to use a different port.
Setting up a connection can be done in 2 ways.
First, the server listens on the public port for any connections to initiate the link that is going to be made. Then one of the following two things happen:
- The server creates a new socket using a different port and replies with: please connect to this port.
- The server asks to which port on your side it can connect, and connects to that.
The difference here is that with the first, all connections are outbound from the client side, thus no ports needs to be forwarded on the router. Whereas the second item uses an incoming port that needs to be configured.
The difference in technique is basically a matter of bandwidth vs opening ports on the clientside.
Now, when from the outside, a connection is being made to your public IP, on any given port, your router will accept the port, and using the internal rules (routing) it will forward the communication to a client ip on the local network. If you are hosting a server, the connection will then be closed and resumed on a new port, freeing the public port.
As long as the port remains open, a new connection cannot be made, and thus the source will keep trying depending on the time-out settings until eventually it gives up, and a time-out occurs.
So basically what you want to do is creating rules for all ports on your router to forward data to your program, and let your program open the connection, and forward it to the new ip. This basically means you create a router yourself. As a result, your speed will slow down and if not done properly, connections may not terminate properly etc.
Basically you are creating a program that most likely the firewall/portforwarding rules on your router can do too.
https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers – Tetsujin – 2015-06-15T09:16:16.463
65535 available ports... What could you possibly be running at any one time that requires all of them?! – Kinnectus – 2015-06-15T09:18:15.933
I was thinking of circumventing symmetric NAT by creating a socket for every single port, and then using a thread pool of the maximum number of threads the JVM could handle to send packets out of every single port using the entire thread pool for concurrency. But that would exhaust every single port in the router and anyone else who wishes to use the router might have their packets dropped. – Sacha T Red – 2015-06-15T09:26:42.043
@SachaTRed - So you want to basically perform a DDOS attack? I hope you understand the University will know EXACTLY WHO does something like this, so please don't, what possible reason could you have? – Ramhound – 2015-06-15T11:00:18.883
umm... I am testing my own RTP client and I don't want to use TURN because amazon AWS charges extra money for server bandwidth usage. – Sacha T Red – 2015-06-15T16:13:17.737
Although if you take up less than all ports. it might be possible to just cycle (take up the first 20%, try, release the first 20%, retry on the next 20% until you manage to get a packet through). This probably won't be necessary on a university WiFi because their symmetric NAT has a predictable port mapping scheme (it increases my port number by 1 every time I reconnect, so I can just guess the next port), but with the 3G/4G cell phone tower, it basically picks a random port, so making a connection with STUN is like a lottery. – Sacha T Red – 2015-06-15T16:17:31.323
But yeah, the IT guys would probably kill me if I accidentally caused a denial of service. But like I said, predictable port mapping schemes are well... predictable and cell phone station towers probably have multiple IP addresses and can just switch if they max out on used ports (since they have more than 65k cell phones connected to a tower anyway) – Sacha T Red – 2015-06-15T16:24:11.663