DefNet - Defold networking modules

Thanks much @britzl , especially for the examples.

I would like to register my interest also, for any further related information; I’m especially interested in the inter-netting of devices via bluetooth(I assume this will have to wait until the ‘plugin-system’ is developed).

My intended application of Defold engine is in real-time, inter-device educational software, for the classroom.

Thx,
Anna

2 Likes

Exactly Anna! Once we have the extension system in place it should be possible to create a bluetooth extension of some kind. I assume you want to use bluetooth instead of wifi because the classroom doesn’t have any wifi?

One of the FutureGames students found this bitstream library to use in his game project:

It also has support for high level messages and message deltas. I haven’t tried it myself but it seems like it could fit in nicely with a TCP or UDP socket solution.

Yes, and also because during prior tests I have found the wifi to be unreliable/high-latency. We have resolved this by providing battery powered wireless access points which the teacher can place anywhere , including when outside the class; I would like to eliminate this dependency.

2 Likes

Hey @britzl, if it possible can you extend this module with more specific examples. Say, how to setup a server + client_01 + client_02 structure for a simple platformer (or any other) game and replicate character position from the client_01 to the server and then to the client_02.

I mean with the current example I can understand (more or less) how to launch server and client, but I have no idea how to deal with, for example, a character position or health.

1 Like

@Hio: I’ve created a local network multiplayer example here: https://github.com/britzl/defnet/tree/master/examples/multiplayer

The example will listen for an instance of the application acting as a host or announce its presence as a host for other clients to connect to if no host is currently broadcasting on the local network. When the host receives a connection its is forwarded to all the other clients. The clients themselves communicate directly with each other and repeatedly send a heartbeat message to the host. If a client is shut down or for some other reason is unable to send heartbeat messages it will be removed and the other clients will be notified.

There’s plenty of room for improvement, and I’m really no expert in network coding, but hopefully it will at least give you an idea!

17 Likes

Wow! :open_mouth: I didn’t expect you to give me working example within only two days. Thanks!

5 Likes

@britzl add DefNet to Assests pages.

2 Likes

Hey Britzl, I’m working on a new mobile game. I want to have a play mode where 2 people can play against each other on seperate phones. Can I set that up with the code/info that you’ve linked to here? Pretty much I just want to know if the aforementioned set up is possible, before I get too carried away. Cheers

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.