免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 7795 | 回复: 11
打印 上一主题 下一主题

[C++] 如何写一个简单HTTP服务器 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-21 16:36 |只看该作者 |倒序浏览
请教如何用C++写一个简易的HTTP服务器,UNIX下。如果要支持ASP或者PHP又需要如何改进?

[ 本帖最后由 huzheyi 于 2008-4-21 16:41 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-04-21 16:43 |只看该作者
如果我猜的没错的话,这个是深信服的在线题目吧?

论坛徽章:
0
3 [报告]
发表于 2008-04-21 16:52 |只看该作者
好奇怪,这个如何编写应该如何回答

论坛徽章:
0
4 [报告]
发表于 2008-04-21 16:58 |只看该作者
看RFC文档看HTTP协议先吧,

论坛徽章:
0
5 [报告]
发表于 2008-04-21 17:01 |只看该作者
如果是我遇到这到题目,我不知道是应该回答什么,不知道回答文件目录索引的处理,还是回答输出http header关的东西

如果谁知道,还请写出标准答案??

论坛徽章:
0
6 [报告]
发表于 2008-04-21 17:05 |只看该作者
<<unix-linux编程实践教程>>
有一个简单的HTTP服务器的例子

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:53:172015亚冠之水原三星
日期:2015-06-02 16:34:202015年亚冠纪念徽章
日期:2015-10-19 18:13:37程序设计版块每日发帖之星
日期:2015-11-08 06:20:00
7 [报告]
发表于 2008-04-21 17:25 |只看该作者
我就会写HTTP服务器,别的不会,而且写出来也不支持ASP,PHP,但是动态内容可以内嵌.

论坛徽章:
0
8 [报告]
发表于 2008-04-21 17:51 |只看该作者

回复 #7 xinglp 的帖子

能否指点一下,这是我的一个作业,不知道如何入手

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:53:172015亚冠之水原三星
日期:2015-06-02 16:34:202015年亚冠纪念徽章
日期:2015-10-19 18:13:37程序设计版块每日发帖之星
日期:2015-11-08 06:20:00
9 [报告]
发表于 2008-04-21 18:50 |只看该作者

回复 #8 huzheyi 的帖子

找个抓包工具,看看请求一个网页的时候都有那些数据交互,这样实现一个简单的,然后根据HTTP协议的规范逐渐完善.

你可以用strace 跟踪附件中的简易程序来看看具体实现,(没有源码,只能在Linux上运行)

[ 本帖最后由 xinglp 于 2008-4-21 18:52 编辑 ]

Httpd.tar.bz2

9.26 KB, 下载次数: 69

论坛徽章:
0
10 [报告]
发表于 2008-04-21 19:24 |只看该作者

nweb

http://www.ibm.com/developerworks/systems/library/es-nweb.html


nweb: a tiny, safe Web server (static pages only)  
Level: Introductory

Nigel Griffiths (nag@uk.ibm.com), pSeries Advanced Technical Support, London, UK, IBM 


10 Jun 2004
Updated 25 Sep 2006

Have you ever wondered how a Web server actually works? Experiment with nweb -- a simple Web server with only 200 lines of C source code. In this article, Nigel Griffiths provides a copy of this Web server and includes the source code as well. You can see exactly what it can and can't do.
Introduction

Have you ever wanted to run a tiny, safe Web server without worrying about using a fully blown Web server that could cause security issues? Do you wonder how to write a program that accepts incoming messages with a network socket? Have you ever just wanted your own Web server to experiment and learn with?

Well, look no further -- nweb is what you need. This is a simple Web server that has only 200 lines of C source code. It runs as a regular user and can't run any server-side scripts or programs, so it can't open up any special privileges or security holes.

This article covers:

What the nweb server program offers
Summary of C functions features in the program
Pseudo code to aid understanding of the flow of the code
Network socket system calls used and other system calls
How the client side operates
C source code

nweb only transmits the following types of files to the browser :

Static Web pages with extensions .html or .htm
Graphical images such as .gif, .png, .jgp, or .jpeg
Compressed binary files and archives such as .zip, .gz, and .tar
If your favorite static file type is not in this list, you can simply add it in the source code and recompile to allow it.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP