multiple clients from localhost

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
stepps
Prole
Posts: 19
Joined: Mon Feb 08, 2021 8:57 pm

multiple clients from localhost

Post by stepps »

I have basic client server working on localhost using built-in luasocket over udp.

However, since my game will eventually be multiplayer, lot of clients connect to one server,
I need to debug how that would work, but on my own machine. I can't figure out how to achieve
that, in other words: open server, open client1, open client2

but the problem is client2 doesn't receive the info from the server, only client1 does, so im
assuming it's not possible to have multiple instances of a client on localhost or it is, but
I maybe need another udp lua library? or can do it with luasocket but some other way?

If someone can help me, I don't know how else to debug my game otherwise, i only have one
computer. If you can post some snippet code how it would work, would be awesome, so from
perspective of server, client1 and client2.

Thanks!
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: multiple clients from localhost

Post by ivan »

Hello.
Yes, it's possible for your server to interact with more than one client. This is achieved using the udp:sendto() function - please refer to my tutorial for more information: https://2dengine.com/?p=networking#Server
You are definitely going to need at least two computers to test your game properly. Note there are several more advanced issues (involving network address translation) when you run your script over the real internet that do not exist when testing on the same machine or the same local network. From my experience, it's nearly impossible to get two machines to connect using UDP over the internet without some sort of an intermediate server.
User avatar
togFox
Party member
Posts: 764
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: multiple clients from localhost

Post by togFox »

ivan wrote: Sun Dec 05, 2021 12:59 pm From my experience, it's nearly impossible to get two machines to connect using UDP over the internet without some sort of an intermediate server.
I use sock.lua which uses enet which uses UDP and my proggy works on LAN but not internet so my experience aligns with your own.

If UDP is too hard for genuine P2P then can someone suggest something else?
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: multiple clients from localhost

Post by grump »

"Pure" P2P is a hard problem regardless of network protocols. You always need some kind of intermediary for peer discovery at the very least, because you can't expect your users to deal with peer adresses and route configuration.

Even if you got the discovery part down you still have to get around NAT. Roaming mobile users are another PITA you sometimes have to deal with.

https://en.wikipedia.org/wiki/STUN
https://en.wikipedia.org/wiki/Hole_punc ... etworking)
https://en.wikipedia.org/wiki/UDP_hole_punching
stepps
Prole
Posts: 19
Joined: Mon Feb 08, 2021 8:57 pm

Re: multiple clients from localhost

Post by stepps »

ivan wrote: Sun Dec 05, 2021 12:59 pm Hello.
Yes, it's possible for your server to interact with more than one client. This is achieved using the udp:sendto() function - please refer to my tutorial for more information: https://2dengine.com/?p=networking#Server
You are definitely going to need at least two computers to test your game properly. Note there are several more advanced issues (involving network address translation) when you run your script over the real internet that do not exist when testing on the same machine or the same local network. From my experience, it's nearly impossible to get two machines to connect using UDP over the internet without some sort of an intermediate server.
Thank you, I will check it out and see what I can do. I also found another article related to maybe what I want
to do, so will check that out, and also saw some other UDP libraries, so maybe try them as well. Will report if
I need more help. Thanks for now guys!
stepps
Prole
Posts: 19
Joined: Mon Feb 08, 2021 8:57 pm

Re: multiple clients from localhost

Post by stepps »

I attached what I am trying to do. Client2 is not receiving message from the server, how to fix that?
Keep in mind this is just example with luasocket, for me doesn't matter what library is used as long
as I can accomplish this basic scenario, otherwise can't continue my multiplayer game, cause this is
fundamental to implement. So if you guys can show me in whatever library or even luasocket somehow
how to do this, would be awesome! Thanks!
00000basicUDP.zip
(1.77 KiB) Downloaded 84 times
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 16 guests