I’m looking at using Legato to implement a socket server, but I’m not clear on how to ‘unroll’ the ‘listen()’ call from a blocking call in COMPONENT_INIT() - which is bad.
Conventionally, I would:
fd = socket(...); // open a socket
bind(fd, ...); // bind the socket to an address
listen(fd,...); // block waiting for an inbound connection
accept(...); // accept the new connection and process
So, any thoughts on how to set up the listen - accept stage of the process in Legato … preferably without using threads?
Another way around it is to start a new thread for the binding and then use yet another thread for each of the incoming connections. This trick I have used with great success. Remember that when you make a new thread you need to connect to all the legato interfaces you which to use in that thread.
@lotam I am using the same app and it works well when sending data to the ecm0 interface (using wp7702 on FX30) but it doesnt when I try to connect trough eth0 (which I have set to static IP). so the ecm0 has IP 192.168.2.2 while eth0 is 192.168.0.31 telnet 192.168.2.2 8999 works telnet 192.168.0.31 8999 doesnt works
but I can ping both IP from the machine which is trying to telnet into the server socket.
Any idea about what is the problem with this? It seems more related to the OS then the socket implementation.
Any advise?
I want to use the cellular interface as default network interface, but I also thought that socket should get messages from any network interface by default
I have added the rule I need to the iptables and saved it with iptables-save, but after reboot it seems that the whole tables go back to default.
Is there a specific way to save the iptables on the legato?
it does work, but I was wondering if there is any way to have this executed by the app itself?
I assume the app will execute with user rights while to run the iptables you will need to be root, but just wondering if there is any way around that.
you can run an unsandboxed application to run your commands by system() API.
When module power on every time, it will automatically run this unsandboxed app.