开发者

Making web server in C with native scripting support

I'm an intermediate C developer, trying to get better. I want to make a very basic and lightweight HTTP server with its own scripting language.

Could I use something like Lua for scripting? If not, what?

I don开发者_运维百科't want to use CGI/FastCGI like Apache does for PHP in most cases, I want my server to natively support my scripting language.

Edit: I want the scripting language to be my own, so I can decide on the syntax, etc.


Why couldn't you use Lua for scripting? Its a scripting language implemented in C, replete with the necessary API.


What do you really want - do you want to create a new language and have a web server for it? Then write web server in that language, that proves that language qualities best :)

Or do you want to write "general purpose" web server and have a scripting language to configure its behavior (instead of "classic" configuration files)? Like Lighttpd with mod_magnet does, using Lua for this? If so, you can:

  • write that HTTP web serving stuff yourself; it's not too hard (web server capable of answering GET/POST requests is a typical school project), but there will be years of bug fighting :) if you mean it seriously, or

  • write a module extending some existing web server functionality (like mod_magnet does for Lighttpd), or

  • use some library that implements HTTP server functionality, so you just glue it with your language interpreter; I don't know any, but you can look at https://stackoverflow.com/questions/175507/c-c-web-server-library

But I think that programming language design is much harder task and requires more theoretical background than implementing a HTTP server, so... good luck :)


You can use Python in the scripting side, it's easy to embed the interpreter in your server. Check this. However, you won't be able to change the syntax, but you will not have to take care of the lexing/parsing/...

If you need help embedding the Python interpreter, ask me.


no matter what you want .. almost every webserver (assuming that i dont know about some) are programmed using sockets.. you will have to look into sockets first .. In Microsoft OSes you can use WINSOCK library .. though its kind of difficult to use at first , it will definitely teach you the core of networking ..

There are a number of other tools that you might want to try .. for example : .NET framework provides excellent socket implementation. For linux i guess there is POSIX api , if not you can always use Java sockets ..

There is an excellent book that you might want to read : "Computer Networking , A top down approach" .. The book has discussed in detail about webservers and even has a sample webserver coding meant for educating purposes.. Happy Programming ..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜