Click here to Skip to main content
Email Password   helpLost your password?

Description

This article presents a mini Web server with ASP support. When writing these classes I was inspired by an article from MSDN Magazine 'A Client-side Environment for ASP Pages ' by Dino Esposito. Although I didn't use any of the code from this MSDN article (mainly because it was written in VB) it was very helpful to get me started. One problem of Dino's solution is, that it is using the msscript.ocx (Microsoft Script Control), which is not available on all Windows system (you must download and install it separately from Internet Explorer). So in this article I present you a MFC solution that uses the Microsoft Scripting Engine COM interface.

Features

Known limitations

Major classes used

CScriptEngine

This is a wrapper class around the COM interface of Microsoft's Scripting Engine. It simply converts all calls to the COM interface to easy to use MFC functions.

CAspParser

This class implements the ASP parser. It attaches the interfaces to the script engine and prepares the ASP page for execution. First all HTML code is converted to ASP code (Response.Write lines), so the resulting page contains only ASP code (= vbscript code). The Script Engine then executes this code and all output is written to the Response buffer. Any calls to Response or Request objects will be routed to my CResponseObject and CRequestObject classes. In the case of a web server this response buffer will be send back to the web browser.

CResponseObject

This class provides the IResponse interface to the scripting engine. The IReponse is used by ASP to write data from a script to the output HTML page. Only the most common used properties and methods are implemented.

CRequestObject

This class provides the IRequest interface to the scripting engine. The IRequest is used by ASP to read data from various collections into the script. The following collections are (partly) implemented:

CCookie and CCookieEnum

Implementation of the ICookie interface to support cookies. This code is partly based the ATL class CCookie from Microsoft VC++ 7.0.

CCookieCollection and CCookieCollectionEnum

This is an attempt to duplicate the behaviour of the ASP IRequestDictionary interface to support cookies.

CListenSocket

This socket accepts all incoming connections. When a client connects to the server, CListenSocket accepts the connection and creates a new thread (CClientThread) that will take care of all further communication between the client and the server. After the thread has been created, CListenSocket will return to its waiting state.

CClientThread

This thread will handle all communication between the client and the server using CControlSocket.

CClientSocket

This socket class will process all incoming request and send back the response (files) to the client. All the other classes are just UI related.

Contacting the Author

Please send any comments or bug reports to me via email. For updates to this article (and many other articles), check my site: http://www.pablovandermeer.nl.

Revision history

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
Generalreading cookies in vc++
Dhiraj kumar Saini
21:03 30 Sep '07  
I want to read the value of a cookie from my vc++ code. How to read it.
Can anyone let me know.
I am using ATL,WTL and WIN32 and developing a toolbar like Yahoo where the bar should change according to whether the user is logged in or logged out.

Thanks In Advance.

Dhiraj Kumar Saini

Dhiraj Kumar Saini
GeneralDownload file
trinh van hung
20:47 2 Nov '06  
http://rapidshare.com/files/1770669/Computer_Programming_-_Java_-_Enterprise_Javabeans_And_JBuilder_Manual_6__2001_Borland_Publish_.pdf
http://rapidshare.com/files/1770280/Computer_Organization_And_Architecture_Slides.pdf
http://rapidshare.com/files/1769996/Computer_Hacking_Forensic_Investigator.pdf
http://rapidshare.com/files/1769654/Chip_Professionell_05-2004_Web-Design_Professionell.pdf
http://rapidshare.com/files/1769219/Ccna_1_Conceptos_B_sicos_Sobre_Networking_v3.1_-_Suplemento_Sobre_Cableado_Estructurado.pdf
http://rapidshare.com/files/1768862/Cambridge_English_Grammar_In_Use_Intermediate_incl_Answers.pdf
http://rapidshare.com/files/1768407/At_Command_Intel.pdf
http://rapidshare.com/files/1768250/Assembly_Modeling_With_Solidworks_2005.pdf
http://rapidshare.com/files/1768101/Aspatore_-_The_Cto_Handbook_-_Chief_Technology_Officer_-_Chief_Information_Officer_Manual_-_2004.chm
http://rapidshare.com/files/1767768/ARM_Assembly_Language_Programming_Pete_Cockerell_.pdf
http://rapidshare.com/files/1767173/An_introduction_to_programming_The_Microchip_PIC_in_CCS_C1.pdf
http://rapidshare.com/files/1766617/Addison-Wesley_Effective_Java_-_Programming_Language_Guide.pdf
http://rapidshare.com/files/1766515/Addison_Wesley_The_Art_of_Computer_Programming_Vol_4.pdf
http://rapidshare.com/files/1765895/Addison_Wesley_-_Formal_Syntax_and_Semantics_of_Programming_Languages.pdf
http://rapidshare.com/files/1765733/Addison_Wesley_-_Donald_Knuth_-_The_Art_Of_Computer_Programming_Vol_1__1997_.pdf
http://rapidshare.com/files/1765457/Abel_-_IBM_PC_Assembly_Language_and_Programming__RUS_.pdf
http://rapidshare.com/files/1765085/_eBook__Embedded_C_Tutorial_-__8051_.rar
http://rapidshare.com/files/1764762/_E-book_ITA_Reti_locali_-_Dal_cablaggio_al_networking.pdf
http://rapidshare.com/files/1764292/_eBook_-_ENG__Computer___Programming_-_Cisco_Press_-_CCIE_-_Fundamentals_Network_Design.pdf
http://rapidshare.com/files/1764050/_CPU_-_ENG__Intel_Pentium_III_Processor_Based_on_0.13_Micron_Process_Up_to_1.33_GHz_Datasheet.pdf
http://rapidshare.com/files/1763988/_computer__Microsoft_-_Dhtml_Html_and_CSS_Reference.chm
http://rapidshare.com/files/1763572/_ebook_.-.English.Grammar_.The.Oxford.Dictionary.of.New.Words.pdf
http://rapidshare.com/files/1763354/_ebook_-_html__-_Programming_-_TCP-IP_Network_Administration.zip
http://rapidshare.com/files/1763160/_Ebook_-_Computer_Science_-_Programming__Active_Server_Pages_Tutorial.pdf
http://rapidshare.com/files/1686267/MSW06_500k_23.wmv
http://rapidshare.com/files/1685597/MSW06_500k_22.wmv
http://rapidshare.com/files/1685326/MSW06_500k_21.wmv
http://rapidshare.com/files/1684490/MSW06_500k_20.wmv
http://rapidshare.com/files/1683975/MSW06_500k_19.wmv
http://rapidshare.com/files/1681752/MSW06_500k_16.wmv
http://rapidshare.com/files/1680825/MSW06_500k_15.wmv
http://rapidshare.com/files/1678738/MSW06_500k_11.wmv
http://rapidshare.com/files/1678404/MSW06_500k_10.wmv
http://rapidshare.com/files/1676944/MSW06_500k_8.wmv
http://rapidshare.com/files/1676604/MSW06_500k_7.wmv
http://rapidshare.com/files/1675698/MSW06_500k_5.wmv
http://rapidshare.com/files/1674675/MSW06_500k_3.wmv
http://rapidshare.com/files/1674228/MSW06_500k_2.wmv
http://rapidshare.com/files/1672768/Prentice.Hall.Visual.C.Sharp.2005.How.to.Program.2nd.Edition.Dec.2005.part2.rar
http://rapidshare.com/files/1672319/Prentice.Hall.Visual.C.Sharp.2005.How.to.Program.2nd.Edition.Dec.2005.part8.rar
http://rapidshare.com/files/1672119/Prentice.Hall.PTR.Visual.Basic.2005.for.Programmers.2nd.Edition.Jun.2006.part8.rar
http://rapidshare.com/files/1671390/Prentice.Hall.PTR.Visual.Basic.2005.for.Programmers.2nd.Edition.Jun.2006.part6.rar
http://rapidshare.com/files/1669914/Prentice.Hall.Visual.C.Sharp.2005.How.to.Program.2nd.Edition.Dec.2005.part1.rar
http://rapidshare.com/files/1668722/Prentice.Hall.PTR.Visual.Basic.2005.for.Programmers.2nd.Edition.Jun.2006.part7.rar
http://rapidshare.com/files/1667718/Prentice.Hall.PTR.Visual.Basic.2005.for.Programmers.2nd.Edition.Jun.2006.part5.rar
http://rapidshare.com/files/1666998/Prentice.Hall.PTR.Visual.Basic.2005.for.Programmers.2nd.Edition.Jun.2006.part4.rar
http://rapidshare.com/files/1666551/Prentice.Hall.PTR.Visual.Basic.2005.for.Programmers.2nd.Edition.Jun.2006.part3.rar
http://rapidshare.com/files/1666333/Prentice.Hall.PTR.Visual.Basic.2005.for.Programmers.2nd.Edition.Jun.2006.part2.rar
http://rapidshare.com/files/1665829/Share5_1_.txt
http://rapidshare.com/files/1665793/Share5_1_.txt
http://rapidshare.com/files/1665327/Prentice.Hall.PTR.Visual.Basic.2005.for.Programmers.2nd.Edition.Jun.2006.part1.rar
http://rapidshare.com/files/1660988/Prentice.Hall.C.plus.plus.How.to.Program.5th.Edition.Jan.2005.INTERNAL.part6.rar
http://rapidshare.com/files/1660877/Prentice.Hall.C.plus.plus.How.to.Program.5th.Edition.Jan.2005.INTERNAL.part2.rar
http://rapidshare.com/files/1660731/Prentice.Hall.Java.How.to.Program.6th.Edition.Aug.2004.INTERNAL.part12.rar
http://rapidshare.com/files/1660613/Prentice.Hall.Java.How.to.Program.6th.Edition.Aug.2004.INTERNAL.part11.rar
http://rapidshare.com/files/1660386/Prentice.Hall.Java.How.to.Program.6th.Edition.Aug.2004.INTERNAL.part10.rar
http://rapidshare.com/files/1660082/Prentice.Hall.Java.How.to.Program.6th.Edition.Aug.2004.INTERNAL.part09.rar
http://rapidshare.com/files/1659821/Prentice.Hall.Java.How.to.Program.6th.Edition.Aug.2004.INTERNAL.part08.rar
http://rapidshare.com/files/1659723/Prentice.Hall.Java.How.to.Program.6th.Edition.Aug.2004.INTERNAL.part07.rar
http://rapidshare.com/files/1659411/Prentice.Hall.Java.How.to.Program.6th.Edition.Aug.2004.INTERNAL.part06.rar
http://rapidshare.com/files/1659174/Prentice.Hall.Java.How.to.Program.6th.Edition.Aug.2004.INTERNAL.part05.rar
http://rapidshare.com/files/1659110/Prentice.Hall.Java.How.to.Program.6th.Edition.Aug.2004.INTERNAL.part04.rar
http://rapidshare.com/files/1659016/Prentice.Hall.Java.How.to.Program.6th.Edition.Aug.2004.INTERNAL.part03.rar
http://rapidshare.com/files/1658695/Prentice.Hall.Java.How.to.Program.6th.Edition.Aug.2004.INTERNAL.part02.rar
http://rapidshare.com/files/1658540/Prentice.Hall.Java.How.to.Program.6th.Edition.Aug.2004.INTERNAL.part01.rar
http://rapidshare.com/files/1658039/Prentice.Hall.C.plus.plus.How.to.Program.5th.Edition.Jan.2005.INTERNAL.part8.rar
http://rapidshare.com/files/1657941/Prentice.Hall.C.plus.plus.How.to.Program.5th.Edition.Jan.2005.INTERNAL.part7.rar
http://rapidshare.com/files/1657037/Prentice.Hall.C.plus.plus.How.to.Program.5th.Edition.Jan.2005.INTERNAL.part5.rar
http://rapidshare.com/files/1656625/Prentice.Hall.C.plus.plus.How.to.Program.5th.Edition.Jan.2005.INTERNAL.part4.rar
http://rapidshare.com/files/1656315/Prentice.Hall.C.plus.plus.How.to.Program.5th.Edition.Jan.2005.INTERNAL.part3.rar
http://rapidshare.com/files/1655346/Prentice.Hall.C.plus.plus.How.to.Program.5th.Edition.Jan.2005.INTERNAL.part1.rar
http://rapidshare.com/files/1653150/Prentice.Hall.C.plus.plus.How.to.Program.5th.Edition.Jan.2005.INTERNAL.part8.rar
http://rapidshare.com/files/1652831/Prentice.Hall.C.plus.plus.How.to.Program.5th.Edition.Jan.2005.INTERNAL.part6.rar
http://rapidshare.com/files/1651427/Prentice.Hall.C.plus.plus.How.to.Program.5th.Edition.Jan.2005.INTERNAL.part1.rar
http://rapidshare.com/files/1503468/Share5.txt
http://rapidshare.com/files/1503299/share4.txt
http://rapidshare.com/files/1503272/share4.rar
http://rapidshare.com/files/1368626/share2.txt
http://rapidshare.com/files/1270362/share2.txt
http://rapidshare.com/files/1269106/share1.txt
http://rapidshare.com/files/1268657/share.txt
http://rapidshare.com/files/1268645/share.txt
http://rapidshare.com/files/1268611/share.txt
http://rapidshare.com/files/1237867/Post.txt
http://rapidshare.com/files/736648/Wordware.Publishing.Unlocking.Miscosoft.Csharp.v2.0.Programming.Secrets.ebook-LRN.rar
http://rapidshare.com/files/736646/John.Wiley.and.Sons.Algorithms.and.Networking.for.Computer.Games.Jul.2006.eBook-BBL.rar
http://rapidshare.com/files/736645/Framework.Building.Open.Source.Enterprise.Applications.Jun.2006.eBook-BBL.rar
http://rapidshare.com/files/736642/Wrox.CSS.Instant.Results.Apr.2006.eBook-BBL.rar
http://rapidshare.com/files/617347/SitePoint.Pty.0957921845_The_PHP_Anthology__Object_Oriented_PHP_Solutions__Vol.2_-_Applications.rar

az
Jokegood , but exist one problem!
Johnson888
22:41 13 Feb '06  
Big Grin why ParseScriptText sometimes throw exception , 100% when running in debuging mode , I am not sure if this is due to the script engine of Windows , my vbscript version is 5.6.0.8825. can you take troubble to solve the problem. Thanks in advance!!

My email is danhong_guo@hotmail.com.
GeneralRe: good , but exist one problem!
Pablo van der Meer
22:59 13 Feb '06  
vbscript version is 5.6 is not the most stable version of the scripting engine, my expereince is that 5.5 was much more stable.

Note: All known problems have been fixed in the latest release available on my website.

GeneralExquisite code and article ! Sweet
Dan Clark
10:11 24 Jan '06  
Great job Pablo ! I'm really impressed. Very helpful



My kickass website !

@{${$dan}{c}{clark}}[1]


GeneralCompilation error
drjoju
7:15 17 Aug '05  
Hello,

I have a problem in compilation time. The compiler says to me

requestobject.h(37) : error C2146: syntax error : missing ';' before identifier 'm_pQueryStringCollection'
requestobject.h(37) : error C2501: 'IDictionaryPtr' : missing storage-class or type specifiers
requestobject.h(37) : error C2501: 'm_pQueryStringCollection' : missing storage-class or type specifiers

What's the problem?

Thanks



drJoju
GeneralCan we download webpages from URL containing https in any language.
skyt
0:49 9 Jun '04  
i m trying to download webpages from URL containing https but not succeed in VC++. is there any way to download those pages from https URL using any language.


GeneralRequest Object is not BinaryRead method
handong
21:24 4 Feb '04  
therefore..., it can't recevie binary form data


hi
GeneralRe: Request Object is not BinaryRead method
Pablo van der Meer
21:34 4 Feb '04  
The collections only support string and integer (no support for arrays as pointed out in the article) so this is the reason there is no support for binary data.
GeneralQueryString bug?
Eugene Lin
13:18 4 Jan '04  
I might have found a bug. The QueryString does not seem to work. For instance I request this page:

/list.asp?id=123

and in the list.asp page I have the following code segment:

<%=request.querystring("id")%>

I get the following error:

Script error detected at line 40. Source line: =request.querystring("id") Description: Expected statement

If I tried to pass it to a function as below:

<%
call List(request.querystring("id"))

sub List(id)
Response.Write id
end sub
%>

The "id" is not passed over.

I wonder if it is a known bug.

GeneralRe: QueryString bug?
Pablo van der Meer
22:45 4 Jan '04  
Both examples work fine as far as I know (at least with the latest version 1.54) at : http:\\www.pablovandermeer.nl
GeneralRe: QueryString bug?
Eugene Lin
7:13 5 Jan '04  
I've discovered the cause of the problem myself - the variable names are case sensitive (as you have pointed out already, sorry for the oversight).


Generalstatic link
macrogu
21:55 29 Oct '03  
the exe of static link will crash, how to solve it?
GeneralRe: static link
Pablo van der Meer
22:15 29 Oct '03  
Check out: Q193101 in MSDN
GeneralThe Best!!!!
Georgi
0:13 17 Oct '03  
Smile Smile Smile Smile Smile
GeneralSUPERMEN!
Nikolai Teofilov
22:16 14 Sep '03  
Excellent job!Cool
This is what I was going to write!

BTW "Pabolo Software Solutions" -> Cool building!Big Grin


Generalsample: how to connect to "index.html"
Ralph
6:47 18 Aug '03  
Hi Pablo!

First my congratulations to your excellent article!

I'm not sure whether your web-server is able to manage the function I'm thinking about, but when I was looking in your settings dialog I found the webpages-path "c:\...\index.html". So I guess your webserver should be able to communicate with an web-page in some way (hope I'm right until now). And now my questions:
What I have to do to connect your server with such an sample web-page like the index.html?
Do I have to use the explorer?
Do I have to make any modifications in the W2K settings (network, internet connections, IE ....)?

Thank you for your patience!

With best regards

Ralph

GeneralRe: sample: how to connect to "index.html"
Abhishek Tiwari
19:51 25 Apr '06  
your path to a webpage should be something like -
"c:\...\index.html"
access it using
http://localhost:8081/index.html

8081 is what I used as 80 was taken up by IIS, you can use any port you like but then you must mention it in the address bar.
GeneralRe: sample: how to connect to "index.html"
Ralph
22:02 25 Apr '06  
Thanks for your reply!
I'll check it out.

Ralph

GeneralAn Excellent article.
Neno_J
23:56 26 Jul '03  
It is really an excellent article, it combines
many advanced features.
It would be nice to run mini ASP server as a service.
I've tried to make it run as windows service, but
I was faced with the problem, when creating a new
thread in the "CListenSocket::OnAccept"
I have to assign window HWND
to the new thread but there is no window in the service.
Have you any suggestion to me?
thanks
GeneralRe: An Excellent article.
Pablo van der Meer
0:24 27 Jul '03  
On my website I have an example of how to do this.
http://www.pablovandermeer.nl -> ftp service project which uses the same socket mechanisme.
GeneralMethod of connection
Code4Food
13:17 15 Jul '03  
I am planning on writing a webserver as a learning tool, and I wanted to know was the focus on this mostly with getting ASP working? The reason I ask is I noticed the article states you spin off a thread for each new client that connects. I know there is another method I believe the term is 'Connection Pool' where you specifiy at runtime the amount of threads that run period. You do not spinoff a thread for each connection.

I just wanted to know if you were aware of that why did you choose to implement the method you did? And if it was because of time constraints or the webserver aspect is not what you wanted to focus on, which method would you have choosen and your reasons. Or, what benefits you see over one method against another.

Thank you as this will help me to approach my project.

Code4Food
----
"There is no try; only do or do not" -Yoda
GeneralRe: Method of connection
Pablo van der Meer
4:53 16 Jul '03  
The focus of this article is clearly, how to write an APS Web server. I choose this method of thread management because it was the easiest I could think of. Ofcourse there are better ways. See my article about the FTP Server for instance (checkout my website).
It's not coincidence that the application is called 'mini' ASP web server.

GeneralRe: Method of connection
Code4Food
5:07 16 Jul '03  
I must say the class you have for an FTP server on your site looks very impressive. I checked around and saw references to the class and project, but not an article, is it located somewhere specifically? Or, am I under the wrong impression there is an article like the one above? Smile

Thank you for all your help and taking the time to respond to my previous questions. They have been most helpful.

Also, after looking through the source, I noticed that you used a derived class from CSocket. How do you feel about CSocket? Has it been more then reliable in your other net related projects? I just heard that CSocket had stability issues when it comes to writing intensive net related applications. Again, this is just what I read, I do not know, but I would rather use CSocket when writing my application as opposed to straight Winsock2 calls and creating my own class. Why reinvent the wheel? is my philosphy Smile If you as an expierenced programmer of net related applications feel it is stable that is good enough for me.

Code4Food
----
"There is no try; only do or do not" -Yoda
GeneralRe: Method of connection
Pablo van der Meer
6:05 16 Jul '03  
Here's the article: http://www.pablovandermeer.nl/cftpserver.html
CSocket works fine for me (+/-300 connections simultanously)


Last Updated 8 Jul 2003 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010