[Networking] Server Connecting

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Semeon
Prole
Posts: 36
Joined: Tue Jul 12, 2016 1:35 pm

[Networking] Server Connecting

Post by Semeon »

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 :)
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: [Networking] Server Connecting

Post by Plu »

"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.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [Networking] Server Connecting

Post by zorg »

*Unless of course, you do have those pesky software or hardware firewalls, routers with blocked ports, et cetera, in the way. :3
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 :3True 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.
User avatar
Semeon
Prole
Posts: 36
Joined: Tue Jul 12, 2016 1:35 pm

Re: [Networking] Server Connecting

Post by Semeon »

So if I were to purchase say a server and have it connect to the ip of that server will that work out?
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: [Networking] Server Connecting

Post by Positive07 »

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)
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: [Networking] Server Connecting

Post by Nixola »

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
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [Networking] Server Connecting

Post by zorg »

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 :3True 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.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: [Networking] Server Connecting

Post by Nixola »

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
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 3 guests