Page 1 of 1

multiple clients from localhost

Posted: Sun Dec 05, 2021 10:27 am
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!

Re: multiple clients from localhost

Posted: Sun Dec 05, 2021 12:59 pm
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.

Re: multiple clients from localhost

Posted: Sun Dec 05, 2021 1:35 pm
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?

Re: multiple clients from localhost

Posted: Sun Dec 05, 2021 2:34 pm
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

Re: multiple clients from localhost

Posted: Sun Dec 05, 2021 4:42 pm
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!

Re: multiple clients from localhost

Posted: Sun Dec 05, 2021 10:31 pm
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