cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Adventurer
Adventurer
566 Views
Registered: ‎05-23-2019

Creating a webserver in Linux

Hello all,

I am going to apologize in advance for this question.  I have been trying to figure out how to even get started with respect to creating a web server in Linux.

I found this example which is great, however, it's for bare-metal application:

https://reference.digilentinc.com/reference/add-ons/dmm-shield/webserverdemouserguide?_ga=2.161769276.1628826370.1603404428-96488038.1600272185

I found links that relate to using busybox/http but I could not find how my c application would interact with the webpage. 

I would like to use javascript HTML and CCS possibly PHP for creating my webpage.  I need some help getting started with this.  

 

 

0 Kudos
10 Replies
Highlighted
Moderator
Moderator
546 Views
Registered: ‎09-12-2007

There is a webserver in busybox:

  • petalinux-config -c rootfs
    • base -> busybox -> httpd
0 Kudos
Highlighted
Adventurer
Adventurer
513 Views
Registered: ‎05-23-2019

From my readings busybox doesn't support bulk data transfer. 

0 Kudos
Highlighted
Scholar
Scholar
489 Views
Registered: ‎05-28-2013

You have two basic approaches: use a stand-alone webserver (such as busybox httpd), which can then use CGI to launch a program you write (can be C code), which outputs data to the client. Alternatively, you can embed a web server within your C code, usually via a library such as libmicrohttpd (or many similar ones). Both methods have pros and cons, and both take some time to learn enough to really make a decision.

0 Kudos
Highlighted
Adventurer
Adventurer
337 Views
Registered: ‎05-23-2019

Thanks for your reply. Always appreciate your help.

0 Kudos
Highlighted
Adventurer
Adventurer
280 Views
Registered: ‎05-23-2019

Hello rfs613,

Still on the fence on this topic.  Would running a node js server on my petalinux/Linux image and have a c application communicate through BSD sockets with the node js server along with the web browser?

0 Kudos
Highlighted
Scholar
Scholar
271 Views
Registered: ‎05-28-2013

I don't have much experience with nodejs. But I suspect it would support communicating with your C code via a socket, in much the same way as other web servers would support this too. In fact there are probably multiple ways to do this, all with their own pros/cons.

Perhaps think a bit more about the data you want to exchange between your C code and the web browser. How are you going to represent it, as binary data (not ideal for web browser consumption), as XML/JSON/other? Maybe you are serving up images? Also consider the direction of flow, and the frequency: is it purely from C code to browser, or does data also have to go the other way? Is it one-shot (user reloads the page, or it refreshes periodically) or is it a continuous stream that should appear "live" to the user?

0 Kudos
Highlighted
Advisor
Advisor
267 Views
Registered: ‎01-28-2008

Hi @tahoe250 

  The busybox/httpd server is a basic server that can be used for a generic application, with support for CGI scripting. If you need a more complex server, you can go with thttpd that is not included in the collection of packages in Petalinux but can be added as a yocto recipe. Thttpd is lightweight but more powerful and feature rich than busybox/httpd version.

  If you do need a full fledged web server, the apache server is included in Petalinux and can be added easily with a petalinux-config -c rootfs. Search for apache2.

Thanks,

-Pat

 

Give kudos if helpful. Accept as solution if it solves your problem.
https://tuxengineering.com/blog

0 Kudos
Highlighted
Adventurer
Adventurer
248 Views
Registered: ‎05-23-2019

The end product will be the web browser be the UI for an embedded application.  Will have user input button, text input, system configuration, ADC readings, setting DAC values, uploading files, etc. So, data needs to be continuously updating.  Defiantly data will be bidirectional should be live to the user.  The main application has to be interfacing with custom IP through the UIO driver.

0 Kudos
Highlighted
Scholar
Scholar
210 Views
Registered: ‎05-28-2013

Of the elements you mentioned, I would say that only the "ADC readings" qualify as "continuous". Everything else changes only when the user triggers it, by clicking on a button, or entering some text, etc. These can be handled by basic CGI scripts (where "script" can mean C code which talks to your application via a BSD socket if you wish). Or equivalently you can invert this and embed a web server in your C code, which can be more convenient.

The ADC reading is slightly more complicated, depending on how fast you want it to update, and how many clients (web browsers) may access it simultaneously. In the old days, the client would poll repeatedly, making a new request each time. This can happen in the background using "AJAX" so the user won't really notice, they just see the value change on the page. If you take care to keep code reasonably efficient, you should be able to handle 100 requests per second, which is probably more than you need. This can be done using CGI, or an embedded web server.

It starts to get more complicated when the number of clients (web browsers) grows, or the refresh rate needs to be higher. There is a relatively high overhead in starting a CGI scripts, or even just establishing a new TCP connections, just to transfer a few bytes of readings to a client. Using more modern web technology, such as "websocket", can help here, by essentially allowing each client to open a pipe that remains open. Then both sides can exchange packets, very much like BSD socket, however encapsulated and transported over HTTP. If you need this level of data flow, then your web server now needs support for websocket (meaning a larger more complex server).

 

If you are doing this work yourself, and are not very familiar, I would suggest to start small, learn the fundamentals. Avoid the latest framework-du-jour, don't believe any of the "our magic product does everything you need" marketing fluff. You don't want to learn the innards of some framework that will be obsolete next month (that really is the velocity of web development these days, sadly). The basics change much less frequently, you would want to focus on understanding HTTP requests, how they are structured (headers followed by body), the difference between GET and POST, etc. Check out an earlier post I made on this topic: https://forums.xilinx.com/t5/Embedded-Linux/webserver-data-user-interface-with-busybox/td-p/1054117 (and countless more from other people too)

Highlighted
Adventurer
Adventurer
138 Views
Registered: ‎05-23-2019

Hello rfs613,

Thank you for your guidance; always the best explanations.  But I think I will be giving node js a shot as I see its mechanics. I have successfully installed it into my build.  

0 Kudos