DefNet - Defold networking modules

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?

Things get more complicated if you want to run Defold as a server and accept websocket connections. Iā€™m not aware of a Lua websocket server at least.

If you can live with mobile and desktop it gets easier since you only need to care about normal TCP and/or UDP connections.

How much logic do you need on the server?

I will probably try it, just to try it - as a long term project.:smiley:

I could live with this is. In fact, itā€™s what I am working on now. Perhaps if I progress on the other project I could incorporate it in the future.

Very little to start.
The biggest thing right now is json.encode/json.decode on small tables, every sync call.

Well, then a Defold TCP server module should be enough. Thereā€™s an example in DefNet, but you should probably improve and modify it to suit your needs.

Ok, but you need an authoritative server? Youā€™re not just using it to relay data to other connected clients? You will actually do some processing and validation of the data sent to the server?

All of the examples are great. Thanks again! I looked at them last year, but was to new to Defold to attempt anything with it.

I donā€™t ā€˜needā€™ one per se. The idea and the possibilities of interacting with the client data interest me though. With the relay server, I end up doing a lot of debugging in the browser console, in addition to Defold.(bleh)

Iā€™ve got DefNet TCP working :slight_smile: This is much better.

1 Like

Hi britzl,

great to have you provide a network library like this with so many examples! I very much appreciate that. I do have a problem using it, though:

I have written a small test application to illustrate my problem (https://www.dropbox.com/s/8uyvnbhfoowrabw/tcptest.zip?dl=0). I start it on two different machines, selecting in the menu to run it as a tcp server on the one and as a tcp client on the other. Client and server detect each other correctly via your p2p-discovery and should then be able to exchange messages (via the respective menu buttons) and print them in the console.

When I use the test application in server mode and then connect with Telnet as a client (e.g. ā€œtelnet 192.168.178.20 8190ā€), everything works as expected and I can exchange data both ways, from the client to the server and vice versa. However, when I use the test application with the DefNet library as a client, as well, no data ever makes it to the other side. When debugging, it seems that in the tcp_client.lua, in line 97, the program never finds any data, so that the clientā€™s ā€œon_dataā€ function never gets called.

What am I doing wrong?
Any help greatly appreciated.

1 Like

The tcp_client is by default configured to read lines of data (using the pattern ā€œ*lā€). This means that it will read data from the socket until it receives a new line. You need to add a \n to the end of the message youā€™re sending. I think that should solve your problem.

3 Likes

britzl, you are a life-saver :o)
Thanks a lot for your very fast reply: works like a charm now.

4 Likes

what do you use for the multiplayer, Bluetooth or global ?