Connect between LANs

Sorry… I know maybe this related to networking stuffs… but hope can get an answer here coz I find this forum is very active and helpful. My question is Java able to make connection from a PC in a network to another PC even though both don't have a real IP address? or maybe some behind proxy or firewall? Can they form a connection (e.g. TCP) by using the getHostAddress method? The game can connect successfully?



PLEASE …  :?

Java Game Networking (JGN)… search for 'JGN'.

Java has no problem doing that? Is that what you mean? That's cool… thanks … I will look into it…  :smiley:

Any PC has an IP… The WAN IP might be given by NAT and so is shared by all computers on the network, but inside the LAN all computers must have a unique IP. Press Windows Key + R then type "cmd /k ipconfig" and you'll see the IP for the LAN for the PC you're on.

Ya … that's what I want to ask. We can't get the IP and connect to those PCs behind NAT or firewalls… Is there a way? Please …

If you search the JGN forums for "NAT", as I did a while back trying to figure out the same problem, it looks as though it should be feasible if you have some sort of dedicated server that can perform a NAT punch-through.

wakaoz said:

Ya ... that's what I want to ask. We can't get the IP and connect to those PCs behind NAT or firewalls... Is there a way? Please ...

Ah.. I see what your problem is. I thought you meant connect two PCs behind the same NAT. For connecting to PCs behind NAT through WAN you need to set up port forwarding on the NAT.

ThaNKS for the replies!!! hmmm… port forwarding … anyone has any ideas if it is possible to do it in our programs … i mean program it to solve the NAT/firewall problems using Java… any guide/sample? So far I only found something like JXTA which looks a bit too complicated from what I want…  :slight_smile:

Some programs like Vuze, use UPNP to configure the NAT things themselves.

Maybe that can help you somehow.

I don't know if there is some java api to do it tho.

UPNP can help, but not all routers support it or have it enabled by default. In many cases its impossible to set port forwarding if the NAT is not under your control (e.g if you're in a corporate network). The only way that remains is to have the connection established to a common point (like a server) with the ports open, then the server can forward messages from one PC to another PC, even if both of them are behind NAT.

Azureus is Java, so i think there is a possibility to use UPNP with java.


Ya … I have searched around and seen quite a lot of people talking about the server ideas … but … hmmm … has anyone tried JXTA before ? They say it can be used to create a virtual network thingy that can bypass firewall and NAT… sounds complicated and not sure whether it fits what I want … think will just have to give it a try then … thanks for all the replies guys!

Oh ya … by the way … If I can't even get the real IP of the PC … how can I forward the message to it? hmmm … that's my problem too …

You can have your Java client connect to some site like http://www.whatismyip.com/ and get the real IP from there. Thing is, if a computer is behind NAT, then its most likely screwed, unless the user configured port forwarding, but in that case he probably knows how to find his own IP address as well. I don't think using a VPN will help much, you still need at least one computer to which you can connect to. If all the computers in question are behind NATs and without forwarding, then you're out of luck  :expressionless:

OMG … haiz … it's ok then … thanks for the replies~!