I've developed a chat program (chatting+buddy list) where a central server hosts the buddy list and informs the active clients of the state of there buddies. The actual chatting is performed peer to peer like, where the first client is the chat server (and will always be, no handover). When a clients wants to chat, it sends a information message through the server to the other client, with information about how to connect to the chat. Then they connect and the users babble till the end of days (without using the main server).

So, this is working.... with a LAN or clients directly connected to the internet. This is not enough, as the Clients can also be behind a router/firewall/NAT.

I've thought of solutions involving tcp hole punching (like STUNT) or usage of the UPnP functionality of some routers. This was due to the idea, that I need several dynamically allocated inbound ports with the client. All these are not so ideal, with respect to security of the users network.

However, it should be possible that there is one defined inbound port (say: 4711), which directs incoming data to the respective chat(s) at a client. So, if I can get this stuff working, there will be one final but important question:
How to get the public / NAT address of the client?

Can it be retrieved by the central server, after it accepted a socket with

Code:

((InetSocketAddress) socket.getRemoteSocketAddress()).getAddress()

So, first question: Do you think, a "one inbound port" should work (with not too much additional work on the data forwarding)?
Second: If the above should work, does the shown code work, to get the public IP of the client?

03-23-2009, 04:08 PM

MasterD

Well, about the "one port" part, this works :)

However, can anyone affirm the correctness (or malfunction) of the above shown code, when trying to get the public IP of the client?