tcMenu icon indicating copy to clipboard operation
tcMenu copied to clipboard

Support device remotes that connect to an accepting server - IE reverse connection direction.

Open davetcc opened this issue 1 year ago • 13 comments

Is your feature request related to a problem? Please describe. Sometimes, when we need to connect with a server there is a need for reverse direction logic. IE where the board opens a connection to a remote server. This server could be on the public internet, and would most likely need encryption, but that is to be discussed in another ticket.

Describe the solution you'd like That the connection were able to be reversed on both the Java API and the board. There is a library issue to track this, and also in future I will create a C# ticket for this as well.

davetcc avatar Jun 02 '24 07:06 davetcc

I am building out examples in tcMenuJavaApi/src/test/java/com/thecoderscorner/menu/examples they will include both a server and client to exercise this functionality.

davetcc avatar Jun 02 '24 07:06 davetcc

@davetcc I see you added some initial support and examples. I will start building my solution and test this implementation. I will update this thread.

Thanks!

vzahradnik avatar Jun 03 '24 08:06 vzahradnik

I would just look at the implementation for now and feedback on what you think at an overall level. I need to do a bit more work on it yet to get it working properly.

davetcc avatar Jun 03 '24 12:06 davetcc

So far I have integrated your example into a Spring Boot application. TcMenu runs on one port and REST API on another. This required building the JavaAPI library from sources but it wasn't complicated.

I also found out that the interoperability with Kotlin is well supported in Spring. Therefore I use that. image

vzahradnik avatar Jun 03 '24 12:06 vzahradnik

Tomorrow I will create a dev branch in my Arduino firmware and after that I will provide some feedback.

vzahradnik avatar Jun 03 '24 12:06 vzahradnik

First observation,

I assume the ClientEthernetTransport will be included into the code via the generator where user enters the IP address and port. Since the IP address is a string, it will help if TcMenu supports entering a constant instead of the string. This would be similar to setting the project name.

IP address will change between environments and having this option will help users better manage this situation.

vzahradnik avatar Jun 03 '24 13:06 vzahradnik

With the latest commit I had it working this morning.


I assume the ClientEthernetTransport will be included into the code via the generator where user enters the IP address and port. Since the IP address is a string, it will help if TcMenu supports entering a constant instead of the string.

Agreed, I will give the option of a variable or constant.

IP address will change between environments and having this option will help users better manage this situation.

Agreed, it would be somehow configurable, at least as a property. I would imagine it would in most cases point to a DNS entry, IE a host name. Will check what happens if a DNS name entry is passed to the connect call.

davetcc avatar Jun 04 '24 12:06 davetcc

OK, I will test that as well. I was also thinking about connection retries.

Imagine the network is not available when the TcMenu is initialized. In the normal scenario an app will connect on demand to the device and it will either work or fail. However, when we have a server, it is necessary the device makes periodic attempts to connect to the server.

What is the current behavior? I'm not that familiar with the TcMenu network code.

vzahradnik avatar Jun 04 '24 12:06 vzahradnik

It looks like the connection is re-established after a network failure or something. I have a successful connection. image

vzahradnik avatar Jun 04 '24 14:06 vzahradnik

I have another observation. Who sets the heartbeat interval in this case?

Irregards of who sets it, it should be configurable (i.e., not set in the generated code).

Receiving a heartbeat every 1.5 seconds is OK for a local connection but it utilizes the server too much. Imagine having 1000 connections sending heartbeat so often.

By default - for this mode of connection - I would say a heartbeat once per 30 seconds is reasonable, maybe even a minute.

vzahradnik avatar Jun 05 '24 06:06 vzahradnik

The logic is the same as for the other device cases, the device sets the interval, and it is configurable at the moment by compiler definition. I think yes, it should be configurable per connection, the current situation is not great, and I will make that change so that it can be configured per connection. The memory overhead for that is minimal. I will see how much work it is to expose on the properties of the code generator.

davetcc avatar Jun 05 '24 07:06 davetcc

The latest commit on the library allows the heartbeat frequency to be adjusted. It is so trivially simple to set manually that I am inclined not to try and add this to the code generator.

davetcc avatar Jun 06 '24 07:06 davetcc

I checked the commit and as you say, it was trivial. I like this change.

vzahradnik avatar Jun 06 '24 10:06 vzahradnik

This is now working in both Java and C++/device. Closing this issue and we'll open additional new ones as it is productionized.

davetcc avatar Jul 28 '24 07:07 davetcc