How can I connect to a Sinatra web application through a Unix socket?

I am writing a web application using Sinatra on an embedded device and should be able to send and receive data through a Unix socket into the embedded code running on the same device. Most likely, we will use JSON for the data format, but I have not found an example that really illustrates how to install this and associate it with a web application.

I am looking for an example of code that will listen on a socket, as well as an example that shows how to get this data on a Sinatra web page. I saw bits and pieces of both, but nothing ties the concepts together.

+4
source share
2 answers

I did not do this personally, but I know Event Machine supports working with a unix socket. The advantage of an event machine is that you can have code listening on a socket without β€œinterfering” with the Sinatra web server. Thus, you can, for example, listen to a socket for some statistics, store these statistics in memory, and then return them to clients by HTTP requests.

And if you are going to EventMachine, I suggest using thin as your web server, which is implemented on top of it so that you do not need to run it manually.

+2
source

I have never done this in person, but Unicorn can listen on unix sockets and can be used for Sinatra applications .

+1
source

All Articles