Are there any problems with this approach to not using a server?

Hi!

As many of you know I am currently building a machine to project visuals synchronised with music. This means I need a defold app with two windows: One window with the visuals which would projected behind the band or DJ, and another with the user interface, which the public won’t see.

To avoid latency, the user needs to interact with the visuals app, and read the information from the UI. That means the visuals app needs to send info to the UI app, NOT vice versa (It’s not a problem if the UI has a delay, but the visuals need to respond to button presses the instant the button is pressed).

All of this will be done on one machine - my macbook pro - without the need to connect to the internet. Just to give you an example of a perfectly working set up i have right now, I control the visuals and use the debug read out as a UI.

my new improved solution is to simply build two apps, a visualiser and a UI, and both apps would share the same save file. The UI could, for example, check the save file every 0.2 seconds to see if any changes have been made, and show them to the user. Think of it as a messaging system between the two apps.

I’d like to put this forward to the community because it will take me a long time to build this solution (i am not a very good programmer) and it would save me a lot of time if some genius could say “that won’t work because defold save files are only readable by the app that saved them” or “loading a save file every 0.2 seconds is unworkable” or something like that.

Thank you so much for your time.

2 Likes

The better solution to this problem would be to add a TCP server to the visualisation app, make it listen to the loopback interface (127.0.0.1), then connect the UI to it as a client.

The loopback interface is FAST. You shouldn’t have any visible lag.

Check out britzl’s DefNet. It has an easy to use server and client:


4 Likes

@dapetcu21 's solution is better(raw tcp is faster I guess and it listens the socket all the time) but you can also try this http server: https://defold.com/assets/tinyhttp/ It is quite fast on local network(especially if they are wired).

2 Likes

The problem here is that I said I wasn’t exactly sure how to do save and loading from a text file; and you have suggested something which is considerably more complicated than that. I haven’t even finished doing the homework that @dapetcu21 set for me yet.

I am going to try my thing and see if it works first.

1 Like

sys.save(your_filename, some_table) and local some_table = sys.load(your_filename)?

1 Like

Ah! ok, sorry. do your homework first :slight_smile:

1 Like

The file pooling method should work, however it won’t be the most reliable time-wise. The problem is that inherently, a file needs to be locked to be written to. So your 0.2s pooling could fail occasionally, and turn your input delay into 0.4s or even more.

If both applications are to run on the same machine, then your ideal option would be OS pipes. One side would have the writing end, the other one the reading end. Communication should be instant, on each frame you can check the pipe for data.

However I’m not sure if or how pipes would be possible in Defold. On top of that they wouldn’t work anymore if you decided to move the two apps to different machines. I believe a simple socket would be your best bet, as the other guys said :slight_smile:

1 Like

A socket on the loopback interface is effectively the same as an OS pipe (plus a tiny bit of overhead from the TCP and IP headers). You’re only bound by how fast can the CPU copy data from one memory location to another. So speed and latency should not really be the issue if you’re running it on the same machine.

3 Likes

@88.josh just don’t be scared of the solutions we are proposing you, really :wink: I’m also not a person that is very familiar with servers etc, but I used once tinyHTTP by @selimanac and it’s really easy, give it a try and if there will be any problems, tell us and we will help :wink: and I really think it would be the easiest solution for you, even easier than sharing a common file (there could be a lot of problems with synchronisation), check out the example, build client side and open server side in editor and run it, and see how you can send a command from client to server :slight_smile: then you can do whatever you want with that command in Lua script :wink:

6 Likes