Hey,
I've seen many tutorials on how to setup a multiplayer client-server thing, but the tutorials always connect to a localhost, how is it possible to turn into something more "global" for example someone from another place to connect. A fully explained code snippet would be highly appreciated, not asking code because I am too lazy too think of it by myself it is just easier for me to understand. Thank you.
EDIT: I want it for a game that I have been "designing" in my mind and I am starting to get the resources so I can start coding it
[Networking] Server Connecting
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: [Networking] Server Connecting
"localhost" just means "connect over the network to this same machine".
The only thing you need to change to make it connect to some other machine, is replacing the "localhost" with the IP address of whatever other machine you're connecting to. The reason tutorials use localhost is because it takes a lot less work to setup a client/server on the same machine than it does to connect two different machines (especially because of firewalls/hardware in between that might be blocking ports and such things) but the general approach is exactly the same. Any tutorial that works against localhost also works against a remote machine.
The only thing you need to change to make it connect to some other machine, is replacing the "localhost" with the IP address of whatever other machine you're connecting to. The reason tutorials use localhost is because it takes a lot less work to setup a client/server on the same machine than it does to connect two different machines (especially because of firewalls/hardware in between that might be blocking ports and such things) but the general approach is exactly the same. Any tutorial that works against localhost also works against a remote machine.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: [Networking] Server Connecting
*Unless of course, you do have those pesky software or hardware firewalls, routers with blocked ports, et cetera, in the way.
There's a reason why Hamachi is/was popular with multiplayer... well, let's say minecraft; even if it slowed the connection because it introduced additional hops for the packets to travel to, it was able to connect two remote computers in a way so they seemed to be in a local area network, hence, easier multiplayer. (Not the only use for hamachi, mind you, but older games like Unreal Tournament could solve these issues by themselves, without relying on such external programs)
There's a reason why Hamachi is/was popular with multiplayer... well, let's say minecraft; even if it slowed the connection because it introduced additional hops for the packets to travel to, it was able to connect two remote computers in a way so they seemed to be in a local area network, hence, easier multiplayer. (Not the only use for hamachi, mind you, but older games like Unreal Tournament could solve these issues by themselves, without relying on such external programs)
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: [Networking] Server Connecting
So if I were to purchase say a server and have it connect to the ip of that server will that work out?
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: [Networking] Server Connecting
Yes but you need some kind of static IP, normal IPs usually change by time, reconections and your ISP so you need to get a static IP through a provider that can guarantee that, or a way to get the IP from a domain name (not sure LuaSocket supports domain names in TCP, but you could take a look at http.lua from the LuaSocket code), maybe saving the IP in a txt file you can get through http or something like that, search the forums for TrAInsported, he managed to achieve this kind of stuff in LÖVE with LuaSockets and a headless server you can see running in his site
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Re: [Networking] Server Connecting
Yes, Luasocket's TCP does support domain names.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: [Networking] Server Connecting
Another suggestion from me would be touse TCP for such "discovery" reasons only; once the clients are connected together through the server, i'd still use UDP for sending game-related data.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: [Networking] Server Connecting
That depends on the kind of game though. If it's a real-time game, UDP would probably be the best choice with a bit of a careful design; if it's turn-based or anyway low latency isn't strictly required, I'd still go with TCP as it can avoid headaches.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 3 guests