camchenry / sock.lua

A Lua networking library for LÖVE games.
https://camchenry.github.io/sock.lua/
MIT License
173 stars 7 forks source link

Getting the game exposed to the outside world #17

Open leankyr opened 3 years ago

leankyr commented 3 years ago

I have made a small game and I am pretty stuck at networking. I want to expose my game to the outside world. Should I use the public IP of my pc/server? Should I port forward my router? Is there any documentation on that?

thank you in advance

jamesalbert commented 3 years ago

@leankyr this is typically done by:

I would not recommend setting up port forwarding on your router. I would suggest using aws, but look around and see what's right for you. While those three steps listed above are generally enough to get going, these cloud platforms typically offer some sort of ddos protection if you want to think about that later on. You might also qualify for aws's free tier program if you don't need that many recourses.

One last thing, you'll also want to setup your server like so:

server = sock.newServer(<external-ip>, <whatever your port is>)

listening on 'localhost' won't do it, you'll want so it accepts remote connections, not just local ones

Since you can't use '0.0.0.0', if you do launch an instance, see if you can get a static ip that doesn't change on server reboot

MoodyH8s commented 3 years ago

I spent way too much time and too many different sources to really get it working online, so I'm going to post it here for hopefully anyone else needing help to get the specifics on how to make it work (at least for running the server on windows).

For testing purposes , I'd temporarily port forward the 22122 port on your own modem. There's enough out there online about how to port forward, it's easy enough. If you don't have access to something like that, then I suggest doing some research on a cloud service provider and running your server on that. You will need the server's public IP and for the server to run, that's about it.

In the code when creating a new server always use 0.0.0.0 for the server ip. It allows you to connect to your own locally hosted server via localhost when creating a new client and it also allows you to connect to your server by using your public ip.

Finally for "configuring security groups to allow all incoming connections to your server's port": This was by far the most confusing bit (at least for windows.)for me but after doing some digging around in windows I found out that your firewall never allows incoming connections unless a rule is set. To set a rule for your firewall to allow all connections from port 22122 you want to do the following.

I am by no means an expert in Sock.lua nor a networking expert and all of this is for testing purposes and I highly recommend you don't blindly follow my networking solutions as it could cause network security issues.

leankyr commented 3 years ago

@jamesalbert

server = sock.newServer(, ) Whenever I try to create a server with the public IP address I get an error that another server is running. Can my IP be used by someone else?

@MoodyH8s Even though I created a rule on windows on the server side I still cannot connect using public IP address. Should I maybe host on Private IP address? I can make the server and client talk whilst on the same network but when i try to connect otherwise they do not talk.

MoodyH8s commented 3 years ago

When calling server.newServer() you must give arguments for it to start a server. It must contain the i.p you want to start the server on , and the port.

Here is an example: server = newServer(0.0.0.0, 22122)

0.0.0.0 is not just a placeholder. This is the i.p you use to claim that this is the computer you will be running this server on.

Looking at the examples that come with the download of sock.lua will really help understand anything that's not explicitly documented.

For the connecting to your server using your public i.p , make sure you're connecting from a separate network. A quick and easy way to do this is with a laptop connected to a mobile hotspot and trying to connect from your laptop to your server. Connecting to a device in your local network, regardless of sock.lua or any other service, using your public ip can cause issues.

@leankyr

leankyr commented 3 years ago

@MoodyH8s This is exactly what I do but It does not work except for once that for some reason it worked. I wll give it one more try and see how it goes. Thanks for all the help! :)

Ismoh commented 2 years ago

I am pretty sure, you need to forward ports. Also check, if your internet service provider uses DSLite. If so you won't have an external ipv4 or one which is shared.

Besides that I can confirm 0.0.0.0 or * is working fine as @MoodyH8s mentioned.