Local vs Internet Networking

When writing network code for a game, how different does the code have to be - if at all - for networking over the internet and local network.



Say I create a basic server client program:

Server server = Network.createServer(…);

server.start();

Client client = Network.connectToServer(…);

client.start();

etc etc…



Why would this not work over the internet if you know the internet IP address of the server? “whatsmyip.org” gives your internet IP address.

Is there some other factors that need to be accounted for when trying to connect over the internet rather then a LAN connection?

Your router has to forward the port to the actual computer in your network. Look in the manual of your router for “ip forwarding” or “port forwarding”.

firewalls, nat, routers just to mention a few. Usually you needs a server in the internet, that helps with udp tunneling (eg call of duty mw2), or does the whole game logic(unrealtournament).

So is it possible to use JME3 and its networking code to create a game that I can connect to a friend (whether it’s a single friend or multiple) via the internet?

@normen I know about port forwarding, but I’m sure it can’t be as simple as that with the partial code I posted…

I’ve got the code running when I connect to localhost (127.0.0.1) I can dispatch a message from the client and the server receives it. But when I set it to connect to my internet IP it tells me “Connection refused.” or from another computer “Connection timed out”.



How would I create that udp tunneling?



The game I’m trying to make needs up to 8 players connecting. I do not want the searching for games that have open slots or anything. I want it to be simple, you enter the hosts’ IP and then it connects. So your game is always private.



I’m still quite new to the networking side of things. any help or direction on how to get this implemented is greatly appreciated.

Internet and local network is the same protocol, you can bind the server to a specific address too. The rest is normal networking and researchable though :google: :wink:

and how would I start the server on a specific address? There’s no functions on the Server class or the Network one to set an IP address for the server.



[java]

INFO: Hosting UDP connection:0.0.0.0/0.0.0.0:25565.

INFO: Kernel started for connection:0.0.0.0/0.0.0.0:25565.

[/java]



I get that when my server starts… How do I change the IP it is bound to?

Well you specify the name when you create the server, localhost or 127.0.0.1 (or nothing for that matter, using the other constructor) should yield the correct interface though, the one thats connected :slight_smile: Your router has the internet IP so thats why it has to route it forward. As said thats normal networking and the problems are as manifold as the hardware and software setups so we can’t really tell you whats wrong in your network, only give some general hints and keywords.

There isn’t a constructor or Network.createServer function that asks for the server IP to bind on. It asks for the game name, game version and some ports but not an IP.

@nyfinscyf said:
There isn't a constructor or Network.createServer function that asks for the server IP to bind on. It asks for the game name, game version and some ports but not an IP.

Right, actually there isn't anymore. So you have multiple active IP connections on your computer? However with that 0.0.0.0 address, it should still receive all connections and if your browser can go to the internet without a proxy configuration and your router forwards the port (and theres no firewall, antivirus etc, etc, etc) then it should definitely work.
@nyfinscyf said:
There isn't a constructor or Network.createServer function that asks for the server IP to bind on. It asks for the game name, game version and some ports but not an IP.


Why would you want to bind on a specific address?
@nyfinscyf said:
So is it possible to use JME3 and its networking code to create a game that I can connect to a friend (whether it's a single friend or multiple) via the internet?


Yes. http://mythruna.com/ is one example... and the one I rewrote the networking layer for in the first place. :)

Not that I know of. All internet based stuff works on my computer without any funky stuff happening.



I’ve tried this. it’s pretty much the same code that the Network.createServer does but instead I’m using the other constructor for UdpKernel and SelectorKernel to specify a IP address.

[java]

InetAddress addr = InetAddress.getByAddress(IPAddressUtil.textToNumericFormatV4(“xxx.xxx.xxx.xxx”)); //xxx.xxx.xxx.xxx is the internet IP address of the computer which is hosting the server

UdpKernel fast = new UdpKernel(addr, Main.GAME_PORT);

SelectorKernel reliable = new SelectorKernel(addr, Main.GAME_PORT);

m_rServer = new DefaultServer(Main.GAME_NAME, Main.GAME_VERSION, reliable, fast);

[/java]



I get the following error.

[java]

com.jme3.network.kernel.KernelException: Error hosting:/xxx.xxx.xxx.xxx:25565

at com.jme3.network.kernel.tcp.SelectorKernel.initialize(SelectorKernel.java:98)

at com.jme3.network.base.KernelAdapter.initialize(KernelAdapter.java:101)

at com.jme3.network.base.DefaultServer.start(DefaultServer.java:158)

at mygame.Main.myInit(Main.java:102)

at mygame.Main.onAction(Main.java:184)

at com.jme3.input.InputManager.invokeActions(InputManager.java:169)

at com.jme3.input.InputManager.onKeyEventQueued(InputManager.java:455)

at com.jme3.input.InputManager.processQueue(InputManager.java:833)

at com.jme3.input.InputManager.update(InputManager.java:885)

at com.jme3.app.Application.update(Application.java:606)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:230)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)

at java.lang.Thread.run(Thread.java:722)

[/java]



This is probably the only way to specify an IP address, but I’ve got a feeling I’m using it wrong.

Any ideas?

@pspeed So how is it done? I can’t figure out why I can’t connect. As for why I want to bind a specific IP, I was following an idea that normen suggested and because it seems to bind to 0.0.0.0:port which doesn’t seem right.

@nyfinscyf said:
@pspeed So how is it done? I can't figure out why I can't connect. As for why I want to bind a specific IP, I was following an idea that normen suggested and because it seems to bind to 0.0.0.0:port which doesn't seem right.


Binding to IP 0.0.0.0 binds to all IP addresses on the local machine. This is almost always what you want for a game.

If you can't get into your network from outside then it is a router configuration problem and very specific to your router. Can you connect from another machine on your network? (If not then it is a firewall issue on your server box.)

@pspeed Oh well that makes sense… I’ll give it a go and see if I can connect from a different computer. If I need more help I’ll update this thread within the next day.



Thanks everyone for now.

Okay so, when I put it on another computer on our network it can connect through the network. But still no luck with connecting through the internet.

I’ve tried port forwarding my system (the server), even tried putting myself as DMZ on the router. Still says “Connection Refused”

You don’t have to “port forward your computer”. You have to “forward one port to your computer”. I’d say thats still where your issue is when you mess with DMZ things suddenly…

That’s what I meant… forward the port that the application is connecting on to my local IP address. both TCP and UPD.

The only other thing I can think of that’s stopping it from working is the firewall, but surely other games don’t have this much trouble getting through, unless they’re doing behind the scenes things like opening up the firewall and all that before the game actually starts.

@nyfinscyf said:
That's what I meant... forward the port that the application is connecting on to my local IP address. both TCP and UPD.
The only other thing I can think of that's stopping it from working is the firewall, but surely other games don't have this much trouble getting through, unless they're doing behind the scenes things like opening up the firewall and all that before the game actually starts.

They have to, probably they use UPnP.

Okay, well I’ll just settle for LAN working. I’ll look into it again later when the project is further in its development. Hopefully nothing much will change, if it does… well… oh well. haha



Thanks for you help @pspeed @normen