DefNet - Defold networking modules

Hi. It’s hard to say exactly what you need. What kind of game is it? Real-time? Turn-based? Do you need any kind of server logic or is all state on the clients? How should the two players find each other? Via a server-side lobby? Via P2P discovery on the same wifi? Using Bluetooth? Many question, I know, but I need to know more before giving an answer.

Thanks for the quick reply. As of now it’s going to be single-screen RTS, with hopefully a versus option. I’d like people to be able to challenge someone in their immediate vicinity, but if no one’s available then also be able to find some one to battle online if they wanted. I can see that this is going to be a lot of work and my technical knowledge of networking is limited at the moment, so if I had to choose one thing to include it would be the first option i.e. battle someone close by, so maybe a bluetooth option would be the best way to go?

Bluetooth or P2P discovery+sockets could work for your scenario. I’ve been meaning to look into a Bluetooth Native Extension, but for now none exists. An example of P2P discovery can be seen in DefNet and it could be worthwhile for you to look into.

Another option would be to look into the matchmaking functionality of a service such as PlayFab or perhaps Google Play Games and once the matchmaking is done on the server you’d hand over to the clients to battle using direct socket connections without involving any backend. The thing with not having a server is that there’s no way for you to prevent cheating and hacked clients.

3 Likes

Thanks for those options. I’ll investigate and see what I can come up with. This game dev thing is actually getting really fun now. It’ll be good to add some more skills to the repertoire :sunglasses:

2 Likes

Hey @britzl,
thank you for these awesome modules!
I tryed your multiplayer implementation with a Android - Windows and a Android - Andoid setup.
Both times the Server (Game i started first) doesnt receive position messages after the second player joined. But the second player gets position updates from player 1.

I tryed to find the error my self but didnt success…

The multiplayer thing should be seen as a sort of proof of concept thing, not a finished module to drop in and use in production code. For real-time I’d probably look at either Gamesparks RealTime or Photon Engine, or perhaps your own custom server using LuaSocket.

But if i want peer to peer i just need that things for bringing the players together. Or am i wrong?

My plan was to give the players the IP of the opponent and then let them play with help of this module. I do roundbased and not realtime. Like a pvp chess game.

Meh i was rly happy that that finally worked :frowning:

The peer to peer discovery should work reasonably well, at least the last time I tried. Don’t the clients find each other?

They do find each other. Maybe i didnt write my problem understandable.
Later on player should find each other over internet. For that i will use something like Playfab.
But once found, they should communicate with help of this module. But here is the problem. Just one (player 2) from both receives messages.

Are these modules(UDP in particular) available through luarocks package manager? I’ve tried searching for it but I couldn’t find it.

Thank you!

Looks like there is a bug - can’t connect to a non-root websocket on HTML5. Like example.com/websocket_path, network inspector shows it always tries to connect to the root instead.

No. None of my stuff is on LuaRocks since most of it is intended specifically for Defold, and LuaRocks makes little sense for Defold users.

Hmm, I see. Looks like this is where it goes wrong:

Not really sure what happens if you try:

self.sock_connect(self, host .. "/" .. uri, port)

Let me know if you try this!

Ah fair enough. It was my understanding that these modules could be used outside defold as well to spin up a server for example.

Thx

That should be possible, with minimal changes needed, as long as you have LuaSocket.

Sweet, I was hoping to run a UDP server and build the client with Defold!
I’ll have to look into what needs to be changed tho.

Thank you

I get an error making many POST requests to DefNet HTTP server.

ERROR:SCRIPT:/defnet/tcp_server.lua:152: bad argument #1 to 'select' (too many sockets)
stack traceback:
	[C]: in function 'select'
	/defnet/tcp_server.lua:152: in function 'update'
	/defnet/http_server.lua:268: in function 'update'
	/server/http_server/http_server.gui_script:66: in function </server/http_server/http_server.gui_script:65>

Is there any way to configure the socket timeout for POST requests, or to re-use the sockets? Or is that dependent on OS configuration?

Should I not be using this method?

This happens with only 2 clients sending http.request()

I think I’ve answered my own questions.

The number of sockets is an OS thing. I was able to gain improvements on my Windows desktop doing this.

But I don’t think I am doing things the correct way if this is needed… Back to the code window.

Can you describe what it is you’re doing in a bit more detail?

I’m trying to make a basic multiplayer game framework, that updates position in real time. (avoiding anything with an API)

I know there are other options out there, and have tried a few. Colyseus was pretty neat, and worked well. I also spun up a basic node.js websockets echo server - which worked great with the Defold websockets kit. I am pretty sure the python ws-echo server would have yielded the same results.

They all use a ‘middle-man’ in the connection though, which requires it’s own coding and configuration. They may be good options if someone is really good with them, but I loath JavaScript - and python.

So, I’ve read some recent threads about others using Defold as a ‘server’. I’m trying to figure out, how, exactly, that is done.

Which brings me to DefNet :smiley: - about the closest I’ve come. (Great stuff by the way, thank you!)

Eventually I would like launch a Defold ‘server’ on a live webserver (running RedHat), with Defold clients(html5, android, and ios) able to send/receive real time updates. Just trying to figure out the best way (or whatever works). Seems I need something like, a Defold Websockets Server. How are other people doing it?