Non-cloud server multiplayer

TL;DR: Looking for guidance on doing a “non-cloud server” multiplayer game.

Hello all. Happy New Year!

I used to do a lot of Corona development a few years ago, but haven’t touched it in quite a while. I’ve been contemplating doing it again – including resurrecting and updating my old games with the latest version of now-Solar2D.

One of the things I was contemplating was a game where a few people on different devices could play puzzle games together without the need for a costly cloud server (like AWS) to handle the multiplayer aspect. It would be more simple games, more turn-based than anything else. I was thinking that one device could act as the server and the other devices would be clients.

Are there any good tutorials or existing source code for that type of functionality? I searched the forum and most posts on the topics are from at least 2 years ago and many of the links no longer work.

Any suggestions on off-the-shelf code or clear tutorials on this can be done in Lua, even better if Solar2D-specific?

Would appreciate any pointers.

Still trying to decide if it’s worth it to start this new project with Solar2D, or if it makes sense to move to some other platform.

Thanks so much!

-david

My library I created a long time ago still works (at least when I tested it on two macs on my network). Not sure it meets your needs, but you can try it.

I updated the auto lan plugin a few years back, it has a pong demo attached

I also very recently made MultiConnectivity plugin for iOS(will bring to Mac and tvOS soon, but not android due to technical limitations) which uses Apples framework for local wifi and bluetooth commutation offline and without network connection.

^Will update this post with solar2d marketplace link but will mostly likely a be charge 19.99$ for this plugin

Thanks for the update on that. I will definitely check that out.

Appreciate the quick response.

i can make a quick demo app if you need it.

Thanks, Scott. I did see a post on that (I think it was the most recent on the topic) and was planning to check that out. In my initial search, I went to see what that code looked like and it looked complicated and without a lot of documentation so put it aside to explore in the future.

Sounds great, though my hope was to have it work with both Android and iOS, so likely wouldn’t be an option for me. Though $19.99 price sounds very reasonable. :smiley:

Thanks, but let me explore a bit first as I don’t want to ask you to do any work for something I might end up not moving forward with. Right now, I am just figuring out if I want to move forward with using Solar2D, so just making sure that it would be able to (somewhat easily) do what I am hoping. I do appreciate the offer though.

From reading more in the forums, I think the zeroconf plugin might not be what I am looking for as I would like for players to be able to play from different locations (connected over WiFi). So using some sort of gamekey/password sharing to allow players to connect in the game, with one of the devices then acting as the “server”. Sample situation: trivia game where the server device sends all connected devices the question and possible answers, and then, as players lock in their answers on their connected device, the locked in answers are sent back to the server device to calculate who got it right and wrong, keep track of scores, then share the results with all player devices.

And if my quick reading on zeroconf was correct, it would not allow for this internet play, just local play.

But please tell me if I am incorrect.

Yes, that is correct. It is only for local play. As in both have to be on the same network.

I ventured into this in the past; with the ability to set a device as a host/server or a client.
This tutorial should get you started and was kept simple enough.

Now, here are some of the complications. Since you want to connect devices directly and across networks you’ll need to know the host’s IP address beforehand. If the host sits behind a router and that router is configured to forward the specified (app/game) port to the host then there should be no problem (as far as establishing the connection goes), however, this will not likely be the case and you’ll need to deal with NAT. A solution for this would be NAT/UDP hole punching, and it’s not foolproof technique. There is also TCP hole punching but I have not tried.

Since this is all network related, you will encounter them on any SDK/Engine/Library of your choosing, unless it’s circumvented via an established service.

That being said, if both devices are on the same network then you don’t have to deal with those issues. :slightly_smiling_face:

1 Like

That would assume that everybody who downloads the game will know how to hole-punch their routers. Even with clear instructions, most people couldn’t do that.

The first part of the ask is pretty simple. For free, you can set up something in MongoDB Realms (and maybe even Pipedreams) that crates rooms and then stuffs people into rooms with JSON data. Then on the client, you can pull the updates. The server would know nothing about the game or how to score it. I have something similar setup.

The second part of the ask is more complicated and that is why I didn’t mention the first part. Although not difficult, it isn’t generic and would require some domain-specific coding.

For the first part, you can also use Photon. They have a lua library that I think still works, and although not free, I found (a while back) 100 CCU not expiring coupon for 95 dollars. I imagine you can still find those coupons around.

Hole punching is done programmatically, nothing to do with the user and specifically to avoid the configuring of a router.

If you have a middle man it does make things easier; I just elaborated on the problems one would face taking a direct peer to peer route.

1 Like

How would one client find the other client? Client A hole punches a port into a random IP from a provider. How would client B know that the port is open on that IP?

Well, with this method there is no way to “discover” anything. :slightly_smiling_face:

Whoever wants to host will need to get their WAN IP. That can be provided automatically by making certain connection to the internet. The port can be a default value as provided in the app, or have them set their own port in the app, in which case every client would need to input that as well if it’s not the default.

Then, on your connection attempt you’ll need to handle hole punching and transition that into an actual connection. You’re basically tricking the router into “believing” there already is an established connection on whichever port you’re punching through so the router will route the packet accordingly.

For UDP, the host will continue to send UDP packets on the specified port and listen for incoming connections in between. The router sees the traffic going out from your device so an incoming packet in the same port will be forwarded to your device; at least this is the way I have understood it and done it in the past.

The TCP way works by sending packets with a modified header. Didn’t try or look much into it, although it might be easier but I’m not sure whether the host needs to attempt a connection to the client at the same time the client attempts a connection to the host. If that’s case then it makes it more complicated.

1 Like

Thanks all for the continuing discussion.

As pointed out, doing this would likely be quite difficult and not worth the effort, so I think a local-only approach first might be the way to get it going, then if there were sufficient demand and revenue to justify a full Internet connection option, then move forward with that.