Jump to content
  • entries
    8
  • comments
    17
  • views
    15,464

Embedded Web Server Tech Demo


Drew_Benton

2,607 views

 Share

In my last blog post, "Why didn't I think about this earlier..." moment, I talked a little about how cool I thought the idea of having an embedded web server would be in your applications. So, for the past couple of days, I've spent some time implementing the idea and coming up with a simple tech demo alongside Leadwerks to show off the basics.

 

First, I had to code a simple TCP server. This was an easy task for me since I've kind of specialized in network programming for the past couple of years. For this particular task, I decided to just go with a simple select server, limited to 64 max concurrent connections. I went this route because I want something very simple and usable. I didn't want to drag in a boost dependency to use boost::asio since this embedded web server isn't going to function as a hosted web server would.

 

Once I had my simple TCP server coded, I needed to then implement a more specialized HTTP processing server on top of it. The HTTP protocol is not fully implemented in this case because I am not trying to write a full blown web server as much as just a basic one. I have support for simple GETs and POSTs. Since the web browser client handles most of everything else, the simple server just has to send correctly formatted messages to it.

 

At this point, I now have the basics of everything I need for the project. However, I wanted to create a library that would be usable from many languages in the same style that Leadwerks is. So, I spent some time developing a C API along with DLLs that are runtime loaded. This way, end users can easily drop in the library into their projects and remove it if they do not want it with minimal work. I went ahead and made this a full blow library in terms of making sure to document the public API as well as providing the loading code for C/C++ users. It's not in a "final" stage yet, but as I work with it, I find little things here and there to improve.

 

Now that the library is completed though, I can just drop it into a Leadwerks project and begin coding. For the tech demo, I made some simple GET processing logic to handle FPS, UPS, the current frame being displayed, as well as a simple Admin panel that links to the previous three features. It's nothing complex really and it's all hard coded. In future versions, a dynamic content system would really allow for more flexibility. Such a system is possible now, but I'm just taking baby steps in testing out the proposed technology.

 

Here are some screenshots of the project.

 

ss7r.th.png ss6v.th.png ss5.th.png ss4l.th.png

 

1.) When the program is not running and you try to access the server, you will get an error since the server only runs when the application is.

2.) This is the console output after trying to access a page that didn't exist. In this case, the root path which is not currently configured.

3.) Boring 404 not found page implemented for everything that is not currently setup.

4.) The simple admin page.

 

ss3eu.th.png ss2p.th.png ss1e.th.png

 

1.) The output of the frame page, which is a screenshot of the program taken at the time the page was accessed.

2.) Simple UPS page that tells the current UPS on access.

3.) Simple FPS page that tells the current FPS.

 

Here is what the code for that application looks like: http://drewbenton.pastebin.com/XsWRLSk4

 

The UserOnProcess function shows the current API usage of the library that was developed. As mentioned before, everything is hard coded. It'd not take much work to switch over to a dynamic content loading system, but that will come later.

 

Attached is a demo of the whole thing if anyone wants to try it. All you have to do is run the program and then type in: "http://localhost:7777/admin" in your web browser. From there, you can try out the current functionality. Since the "frame" command saves a file to the current directory, make sure to execute the application in a folder where default write permissions are applied if you are on Vista or Windows 7. You can hit Refresh on pages to get updated content as well.

 

I plan on making a new blog post about the embedded web server library itself later after a few more revisions. Overall I am very pleased with how this project has turned out. I see some real potential here and hopefully I can work up some more complicated examples later on to show off possible uses.

 

Check back later for more!

 Share

2 Comments


Recommended Comments

Thanks for the reply!

 

Hopefully it'll be able to be used for some cool things. I''ll have a new post on the library itself soon. I think I've gotten it to a point where I'm comfortable with the features it provides and hopefully it doesn't have too many bugs.

 

There are existing web servers that might be able to be used or modified for such a task as this, but I wanted to have my "own" basic one that provides the simple features needed. I know exactly how this works and I think the design is practical.

 

Anyways, back to work on checking over a few things on the project and then begin writing a new blog post.

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...