How to Setup a bidirectional connection between a Blazor Server and an embedded c device? - c

I'm quite new to .net. I have a Blazor Server application and an embedded linux device with a c application.
Now I want to send different commands from the server to the embedded device and read the results.
What is the best practice here. Could you point me towards an elegant solution?
Is a simple tcp socket (embedded device as client, server as server) sufficient or do I need something like libwebsocket to accomplish my goal?
Regards Martin.

Related

Migrating particular TCP Connection using CRIU tools

Is it possible to migrate a single and particular TCP connection inside a running process in one machine to another machine using CRIU tools in Linux?
What I want is to dump a particular TCP Connection information in a memory and transfer this information to a peer machine. Inside this machine, I will use the dumped information to recreate the the migrated TCP connection. Does anyone have an example or tutorial in c language?
I am aware about different solutions like SockMi which provides Kernel Module + User Space APIs to migrate a certain TCP Socket. However, I want to use CRIU tools since it is part of Linux Mainline.
Right now we only have the TCP migration functionality integrated into CRIU tool. It sits in the sk-tcp.c file, the whole TCP-repair code is there, though it's bound to the rest of CRIU.
On the other hand, we've been asked for TCP-only migration for quite a while, it's possible to pull this code into smth like libcriutcp.so, but it will require patching. You're welcome to participate to the https://github.com/xemul/criu/issues/72

REST and C process integration

I have a need to provide restful api support to a linux deamon process that will maintain and manipulate a in-memory table (simple C structure of arrays). This deamon will act as a configuration entity and will relay the table contents to another process on its bootup or during configuration request.
Now in this context i would be happy to obtain the following information:
Would it be good to have an integrated web server or have an independent web server and talk to this daemon. Please note this server would not be required to handle huge loads.
Please suggest some good web servers with good REST support.
If an independent web server then what is the best mechanism for web server to deamon communication.
Please note this would be deployed on a small embedded board running debian.
Well, a possible solution is based on developing a CGI that is executed by any webserver (apache, lighttpd, ...) . This program connects to the main daemon with an IPC mechanism such as sockets, fifos or message queues and after interacting with the daemons returns the desired output to the REST client.
The CGI program can be written in any language, but if you want to write it in C, check this project: it's a CGI program written in C that takes commands for an IP camera. The connection with a main daemon is not implemented, since it was outside the scope of the project. I like it because it has an embedded XML parser and does not require any external library

How to call solr server from python using unix socket instead of localhost?

I am querying using solr search engine in my webapp. But right now I am calling solr server from python using
"http://localhost:8983/solr/select?q="
But I heard using unix socket instead helps reduce tcp/ip overhead. How to go about it? Thanks in advance.
None of the popular application containers support connections over local unix sockets, and usually for a good reason; it's a very, very, very small part of the request/response cycle, so unless you're actually seeing issues from tcp/ip setup and teardown, there should be very little reason for this.
Client libraries does not support local unix sockets either, as they exclusively talk TCP/IP to the server (and assumes an URL as an endpoint).
You can use EmbeddedSolr to integrate Solr directly into a Java project and use it without any request overhead, but the overhead from a search application will be small compared with the time taken to perform the actual search and handling the application container.

Chat *Server* on Embedded platform

I am currently building a chat server (meebo style).
The architecture is something like this.
Bitlbee over libpurple is on host B. Its a trivial server on data center.
User communicates with bitlbee via web server (just like meebo) on Host A. The backend of this web server maintains chat session. It just translates the user commands to proper bitlbee comamnd and sends back to host A.
The most important part here is that host A will be deployed in embedded Linux.
I have 2 questions.
To keep the chat session persistent I am thinking of using node.js. As its much more easier to create a real time application with persistent connection. But I doubt if its supported in such platform.
If I use C instead of node.js (I am not using any web server) I can talk to the irc server at host A by libirc. But how do I implement all the web server features in C (like session, url/cookie/post data parsing etc) ?
Also if you think my approach is wrong or there is a better approach please tell me how can I improve this architecture?
Note: This is NOT a high volume chat server.
If building V8/Node.js is prohibitive on the embedded platform, the next best thing would be to take the event loop and platform layer (libuv) and HTTP parser (http-parser) of Node, both written in C and use those as a starting point. These are the same libraries used to build Node.js so they are battle tested and will give you the performance characteristics you seek.
Ryan Dahl, author of Node.js, demonstrates exactly how to use libuv and http-parser to build an asynchronous web server in C.
Put a ZNC server between Bitlbee and the web-based IRC client. Bitlbee will think that the user has never logged out and ZNC can maintain a backlog of messages until the user connects again with the web client.
I would try to go with node.js if that is your choice, also what embedded system is it? As knowing that would help more. Also, another plus for node.js is that it does have session handling built it, but if you wanted to do it in C try and see if you can get a sqlite wrapper running on the embedded device to store the session information.
But, if possible stick to something with less work on embedded devices, feels bad to reinvent a lot of stuff or have to fiddle with compile issues for your device.

Save Data using Dynamic C

I am using Rabbit single board computer. I would like to save the data I/O which is connected to another Rabbit single board computer through a wireless connection. Is it able to save the data inside the PC in a .txt file for example?
If you can establish a connection to a PC, and the PC is running some server to log data, yes, you could save to a PC. For example, the PC could run a TFTP server or FTP server on the same wireless network, and you could connect to it from the rabbit SBC and save whatever data you need to.
Yes, this is possible.
There are two parts to this scenario. Your embedded app needs to know how to connect to a server application running on the PC or network, and you must, of course, have said server application running on the target machine.
If you're sending entire files, FTP, as bdonlan suggested, is a good way to go. The protocol is well-understood and you can probably find a library to wrap it for you.
If you need to log data real-time, you'll need to have some sort of application which can receive messages or accept a socket connection, and a protocol to get the text across the wire(less). A web server may be a good way to do this, because you can POST chunks of data to the server with a simple HTTP request, and the server app can decide how to organize and store the information. Once you have a web server running, you may find it beneficial to build some pages that provide basic reporting functionality, so you can see the logged data from any web browser.
This could be less restrictive than FTP, but will require some web development expertise on your part.
Any reasonable solution is going to require that you already have a connection to the wireless network with a correctly-configured and functioning IP stack. Without that, you're probably out of luck connecting to any networked resources.

Resources