I have an Android APP that needs to handle multiple TCP connections, as server-side. Nowadays I know all the possible ports where the clients are trying to connect, so I'm creating TCP socket listeners for each one.
But on the other hand, sometimes I receive connections to some ports where I don't have socket listeners, so the connection fails.
Is there any kind of TCP socket listener that accepts all incoming ports or a way to know when a incoming connection it's been dropped because no socket could handle it?
So, possible solutions I'm thinking are:
Open a generic TCP socket listener that accepts any TCP connection and then create a socket to handle it.
Catch dropped incoming connections to create a socket listener and make them work at the second try.
To have a more specific idea, I'm trying to do a NAT on android, so I need to be listening on all possible incoming connections to handle them and forward to the correct network.
Is it possible to do that on java/android?
Thanks!